HZNU 2019 Summer training 4

Posted smallhester

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HZNU 2019 Summer training 4相关的知识,希望对你有一定的参考价值。

A - Little C Loves 3 I

 CodeForces - 1047A 

题意:一个数分成三份,每一个都不是3的倍数

题解:分成 (1, 1, n - 2) 或者分成(1, 2, n - 3 )

技术图片
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 1e3+7;

int main()

    ll n;
    scanf("%lld",&n);
    if((n - 2) % 3 == 0)
        printf("1 2 %lld\n",n - 3);
    else
        printf("1 1 %lld\n",n - 2);
View Code

 

B - Cover Points

 CodeForces - 1047B 

题意:平面上有n个点,用一个顶点在原点,两直角边分别在x轴和y轴的等腰直角三角形覆盖这些点,问能将这些点全部覆盖的三角形的直角边最短是多长

题解:求解max(x + y)

技术图片
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 1e3+7;

int main()

    int n;
    scanf("%d",&n);
    int maxx = 0;
    while(n--)
    
        int a,b;
        scanf("%d %d",&a,&b);
        maxx = max(maxx,a + b);
    
    printf("%d\n",maxx);
View Code

 

C - Enlarge GCD

 CodeForces - 1047C 

题意:n个数的gcd是k,要你删掉最少的数使得删完后的数组的gcd > k

题解:先求出k,然后每个数除以k。然后找出出现次数最多的质因数即可。

技术图片
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 3e5 + 10;
const int M = 1.5e7 + 10;
int pn;
int gcd(int a,int b)

    return b == 0 ? a : gcd(b,a % b);


int a[maxn];
int num[M];
int p[4000],prime[4000];
void init()

    pn = 0;
    memset(p,0,sizeof p);
    for(int i=2;i<4000;i++)
    
        if(!p[i])
            prime[pn++] = i;
        for(ll j =0 ;j < pn && i * prime[j] < 4000; j++)
            p[i * prime[j]] = 1;
            if(i % prime[j] == 0)
                continue;
        
    
    //cout<<pn<<endl;

int main()

    int n,mingcd;
    init();
    scanf("%d",&n);
    memset(num,0,sizeof num);
    for(int i=1;i<=n;i++)
    
        scanf("%d",&a[i]);
        if(i == 1)
            mingcd = a[i];
        else
            mingcd = gcd(mingcd,a[i]);
    
    for(int i=1;i<=n;i++)
        a[i] /= mingcd;
    int ans = -1;
    for(int i=1;i<=n;i++)
    
        for(int j=0;j<pn && prime[j] * prime[j] <= a[i];j++)
        
            if(a[i] % prime[j] == 0)
            
                num[prime[j]]++;
                ans = max(ans,num[prime[j]]);
                while(a[i] % prime[j] == 0)
                    a[i] /= prime[j];
            
        
        if(a[i] > 1)
        
            num[a[i]]++;
            ans = max(ans,num[a[i]]);
        
    
    printf("%d\n", ans == -1 ? ans : n - ans);
View Code

 

D - Little C Loves 3 II

 CodeForces - 1047D 

题意:给你n*m得棋盘,让你找两点之间距离为3的点的个数,不能重复使用,距离定义,两坐标差绝对值之和、

题解:找规律,找特殊样例即可

技术图片
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 1e3+7;

int gcd(int a,int b)

    return b == 0 ? a : gcd(b,a % b);

int main()

   ll n,m;
   ll ans;
   scanf("%lld %lld",&n,&m);
   if(n > m)
       swap(n,m);
   if(n == 1)
   
       if(m % 6 == 0)
           ans = n * m;
       else if(m % 6 <= 3)
           ans = m - m % 6;
       else
           ans = m - (6 - m % 6);
   
   else if(n == 2)
   
       if(m == 2)
           ans = 0;
       else if(m == 3)
           ans = 4;
       else if(m == 7)
           ans = 12;
       else
           ans = n * m;
   
   else
   
       if(n * m % 2 == 1)
           ans = n * m - 1;
       else
           ans = n * m;
   
   printf("%lld\n",ans);
View Code

 

E - Region Separation

 CodeForces - 1047E 

题意:给定一棵大小为n的树,点有点权,在一个方案中可以将整棵树划分多次,要求每次划分后各个联通块的权值和相等,问有多少种划分方案

 

以上是关于HZNU 2019 Summer training 4的主要内容,如果未能解决你的问题,请参考以下文章

HZNU 2019 Summer training 8

HZNU 2019 Summer training 6 -CodeForces - 622

HZNU 2019 Summer Selection contest 1

HZNU Training 23 for Zhejiang Provincial Competition 2020

HZNU Training 21 for Zhejiang Provincial Competition 2020

HZNU Training 2 for Zhejiang Provincial Competition 2020