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);
}

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);
}

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);
}

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);
}

E - Region Separation

CodeForces - 1047E

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

 

原文地址:https://www.cnblogs.com/smallhester/p/11155896.html

时间: 2024-11-14 12:52:34

HZNU 2019 Summer training 4的相关文章

HZNU 2019 Summer training 6 -CodeForces - 622

A - Infinite Sequence  CodeForces - 622A 题目大意:给你一个这样的数列1,1,2,1,2,3,1,2,3,4,1,2,3,4,5....就是从1~n排列(n++).最后问你第n个位置是什么数字. 思路:如果你花点时间列数列的话会发现,1~n的最后一位对应的位置是1~n的和,那我们就大胆使用二分进行搜索这位数. #include<iostream> #include<algorithm> #include<cstdio> #incl

HZNU 2019 Summer training 6

A - Infinite Sequence CodeForces - 622A 题意:第一个数是1,接下来是1和2,接下来是1,2, 3,接下来是1,2,3, 4,问第n个数是什么 题解:找出第几轮在找出第几个 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector>

HZNU 2019 Summer training 8

A - Petya and Origami CodeForces - 1080A 题意:制造一份邀请函需要2份a物品,5份b物品,8份c物品,一个盒子里面有k份物品(可以为a或b或c)问你制造n份邀请函需要用多少个盒子 题解:加起来就行了 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include &

HDU校赛 | 2019 Multi-University Training Contest 3

2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 1004. Distribution of books 考虑二分答案,设当前二分出来的是\(x\). 设\(f_i\)表示前\(i\)个能分成最多的段数,使得每一段和都\(\leqslant x\). 转移显然,枚举一个\(j\),若\(s_i-s_j\leqslant x\)则转移,\(s_i\)表示前

[最短路,最大流最小割定理] 2019 Multi-University Training Contest 1 Path

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3747    Accepted Submission(s): 1075 Problem Description Years later, Jerry fell in love

HZNU 2019 Summer Selection contest 1

A - Nastya Is Buying Lunch CodeForces - 1136D B - Neko Performs Cat Furrier Transform CodeForces - 1152B C - TV Shows CodeForces - 1061D D - Pairs CodeForces - 1169B E - Increasing by Modulo CodeForces - 1169C F - Good Triple CodeForces - 1169D G - T

2019 Multi-University Training Contest 2

题号 A B C D E F G H I J K L 状态 . . . . Ο . . . . Ο Ο Ο 1005  Everything Is Generated In Equal Probability //#pragma comment(linker, "/STACK:102400000,102400000") #include<iostream> #include<stdio.h> #include<stdlib.h> #include&l

2019 Multi-University Training Contest 1 (补题)

1001.Blank 题意:给一列数组填四种数,使得每个给定第$i$个的区间数的种类刚好有$x_{i}$种 我的思路:dp,状态排完序后是四种数最后的位置,转移时判断合法性即可(卡常有点厉害) 代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int N = 1e2 + 5; 5 const int MOD = 998244353; 6 7 int dp[2][N][N][N]; 8 int a[N][10]; 9

2019 Multi-University Training Contest 3

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int S=8; ll mult_mod(ll a,ll b,ll c) { a%=c; b%=c; ll ret=0,tmp=a; while (b) { if (b&1) { ret+=tmp; if (ret>c) { ret-=c; } } tmp<<=1; if (tmp>c) tmp-=c; b>&g