Codeforces Round #615 (Div. 3)
作者:互联网
题目链接:http://codeforces.com/contest/1294
A. Collecting Coins
题意:有个人有n硬币,要分给a,b,c,三个人,使得这三个人硬币相同,这三个人已经有的硬币数量给出
思路:将n与这三个人硬币数量相加模3,判断是否为0即可,注意分后这三个人的硬币数量不能比以前还少
1 // 2 // Created by HJYL on 2020/1/14. 3 // 4 #include <stdio.h> 5 #include <iostream> 6 #include <algorithm> 7 #include <cmath> 8 #include <vector> 9 #include <string> 10 #include <cstring> 11 #include <iomanip> 12 using namespace std; 13 const int maxn=100+10; 14 typedef long long ll; 15 int main() 16 { 17 int T; 18 scanf("%d",&T); 19 while(T--) 20 { 21 ll a,b,c,n; 22 cin>>a>>b>>c>>n; 23 ll d=a+b+c+n; 24 if(d%3==0&&d/3>=a&&d/3>=b&&d/3>=c) 25 printf("YES\n"); 26 else 27 printf("NO\n"); 28 } 29 return 0; 30 }
B - Collecting Packages
题意:一个人要拿n个包裹,这些包裹放在坐标上,要求他只能右走或者上走,问是否有一条路线能全部拿到包裹,能输出字典序最小的,不能就输出“NO”
思路:将点按照横坐标排序,R字典序比U小,字典序最小就是优先走右,如果排序后下一个点的纵坐标比之前的小,那么就不满足,否则就遍历点,优先R遍历
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<time.h> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 const int maxn=1000+100; 9 struct Point{ 10 int x,y; 11 bool operator<(const Point &other)const{ 12 if(this->x==other.x) 13 return this->y<other.y; 14 return this->x<other.x; 15 } 16 }; 17 int main() 18 { 19 int T; 20 scanf("%d",&T); 21 while(T--) 22 { 23 int n; 24 scanf("%d",&n); 25 Point p[maxn]; 26 for(int i=0;i<n;i++) 27 { 28 scanf("%d%d",&p[i].x,&p[i].y); 29 } 30 sort(p,p+n); 31 bool flag=false; 32 for(int i=1;i<n;i++) 33 { 34 if(p[i].y<p[i-1].y) 35 { 36 flag=true; 37 break; 38 } 39 } 40 if(flag) 41 printf("NO\n"); 42 else{ 43 printf("YES\n"); 44 int xx=0,yy=0; 45 for(int i=0;i<n;i++) 46 { 47 while(xx<p[i].x) 48 { 49 printf("R");xx++; 50 } 51 while(yy<p[i].y) 52 { 53 printf("U");yy++; 54 } 55 } 56 printf("\n"); 57 } 58 59 } 60 return 0; 61 }
C - Product of Three Numbers
题意:给你一个数,问是否有三个不相同的数之积为它,有就输出这三个数
思路:分解质因子,需要一个好板子
1.如果质因子只有一个的话,判断它的次数,如果大于6的话,就满足,例如六个2,就可以分成2,4,8,如果次数没有6那么就不满足
2.质因子有两个的话,判断指数之和是否大于3,只有大于三,才会满足,否则也是不满足
3.质因子三个以上的话,输出前两个和n除以这俩个数之积即可
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<time.h> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 const int MAXN = 1e5; 9 typedef long long ll; 10 int p[MAXN + 5], ptop; 11 int pn[MAXN + 5]; 12 13 void sieve() { 14 long long n = MAXN; 15 pn[1] = 1; 16 for(int i = 2; i <= n; i++) { 17 if(!pn[i]) 18 p[++ptop] = i; 19 for(int j = 1; j <= ptop; j++) { 20 int t = i * p[j]; 21 if(t > n) 22 break; 23 pn[t] = p[j]; 24 if(i % p[j] == 0) 25 break; 26 } 27 } 28 } 29 30 int fac[105][2], ftop; 31 32 void get_fac(int n) { 33 ftop = 0; 34 for(int i = 1; i <= ptop; ++i) { 35 if(n % p[i] == 0) { 36 fac[++ftop][0] = p[i]; 37 fac[ftop][1] = 0; 38 while(n % p[i] == 0) { 39 n /= p[i]; 40 ++fac[ftop][1]; 41 } 42 } 43 } 44 if(n > 1) { 45 fac[++ftop][0] = n; 46 fac[ftop][1] = 1; 47 } 48 } 49 int main() 50 { 51 int T; 52 sieve(); 53 scanf("%d",&T); 54 while(T--) { 55 56 int n; 57 cin >> n; 58 get_fac(n); 59 //cout<<ftop<<endl; 60 if (ftop >= 3) { 61 printf("YES\n%d %d %d\n", fac[1][0], fac[2][0], n / fac[1][0] / fac[2][0]); 62 } else if (ftop == 1) { 63 if (fac[1][1] >= 6) 64 printf("YES\n%d %d %d\n", fac[1][0], fac[1][0] * fac[1][0], n / fac[1][0] / fac[1][0] / fac[1][0]); 65 else 66 printf("NO\n"); 67 } else { 68 if (fac[1][1] + fac[2][1] <= 3) 69 printf("NO\n"); 70 else 71 printf("YES\n%d %d %d\n", fac[1][0], fac[2][0], n / fac[1][0] / fac[2][0]); 72 } 73 } 74 return 0; 75 }
标签:ftop,int,Codeforces,long,615,printf,fac,Div,include 来源: https://www.cnblogs.com/Vampire6/p/12231618.html