Codeforces Beta Round #107(Div2)
作者:互联网
B.Phone Numbers
思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读取就好,在比较的时候也容易比较,直接比较ASCII码就行
代码:
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cstdio> using namespace std; struct people{ int num; char s[100]; int t=0,p=0,c=0; }a[1500]; bool cmpt(people a,people b){ if(a.t==b.t){ return a.num<b.num; } return a.t>b.t; } bool cmpp(people a,people b){ if(a.p==b.p){ return a.num<b.num; } return a.p>b.p; } bool cmpc(people a,people b){ if(a.c==b.c){ return a.num<b.num; } return a.c>b.c; } int main(){ int t; scanf("%d",&t); for(int i=0;i<t;i++){ a[i].num=i; int n; scanf("%d %s",&n,&a[i].s); int t=0; int p=0; int cc=0; for(int j=0;j<n;j++){ char b,c,d,e,f,g; char s; getchar(); scanf("%c%c",&b,&c); scanf("%c",&s); scanf("%c%c",&d,&e); scanf("%c",&s); scanf("%c%c",&f,&g); if(b==c&&c==d&&d==e&&e==f&&f==g){ t++; }else if(b>c&&c>d&&d>e&&e>f&&f>g){ p++; }else{ cc++; } } a[i].p=p; a[i].t=t; a[i].c=cc; } /*for(int i=0;i<t;i++){ printf("%d %d %d\n",a[i].t,a[i].p,a[i].c); }*/ int tt=0; int p=0; int c=0; int sump=0,sumt=0,sumc=0; sort(a,a+t,cmpt); tt=a[0].t; for(int i=0;i<t;i++){ if(a[i].t==tt){ sumt++; } } printf("If you want to call a taxi, you should call: "); for(int i=0;i<sumt;i++){ printf("%s",a[i].s); if(i<sumt-1){ printf(", "); } } printf(".\n"); sort(a,a+t,cmpp); p=a[0].p; for(int i=0;i<t;i++){ if(a[i].p==p){ sump++; } } printf("If you want to order a pizza, you should call: "); for(int i=0;i<sump;i++){ printf("%s",a[i].s); if(i<sump-1){ printf(", "); } } printf(".\n"); sort(a,a+t,cmpc); c=a[0].c; for(int i=0;i<t;i++){ if(a[i].c==c){ sumc++; } } printf("If you want to go to a cafe with a wonderful girl, you should call: "); for(int i=0;i<sumc;i++){ printf("%s",a[i].s); if(i<sumc-1){ printf(", "); } } printf("."); }
C.Win or Freeze
思路:其实最多两局,如果给定的这个数质因子大于2或者是质数,那么就是1赢,1直接选定两个质因子的乘积就能确保自己赢,剩下的情况就是2赢
代码:
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cstdio> #include<vector> using namespace std; vector <pair<__int64, __int64> > divide(__int64 x) { vector <pair<__int64, __int64> > v; for (int i = 2; i <= x / i; ++i) if (x % i == 0) { int s = 0; while (x % i == 0) x /= i, s++; v.emplace_back(i, s); } if (x > 1) v.emplace_back(x, 1); return v; } /*vector<__int64> get_divisors(__int64 x) { vector<__int64> res; for (__int64 i = 1; i <= x / i; ++i) if (x % i == 0) { res.push_back(i); if (i != x / i) res.push_back(x / i); } sort(res.begin(), res.end()); return res; }*/ inline bool isprime(long long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long long i = 3; i <= n / i; i += 2) if (n % i == 0) return false; return true; } int main(){ __int64 num; int flag=0; scanf("%I64d",&num); if(num==1){ printf("1\n"); printf("0\n"); return 0; }else if(isprime(num)==true){ printf("1\n"); printf("0\n"); return 0; } vector<pair<__int64,__int64>> v; v=divide(num); __int64 len=v.size(); __int64 sum=0; __int64 sump=1; int f=0; for(__int64 i=0;i<len;i++){ __int64 se=v.back().second; __int64 fi=v.back().first; v.pop_back(); sum+=se; if(f<2){ if(se>=2&&f==0){ f++; f++; sump*=fi; sump*=fi; }else if(se<2){ sump*=fi; f++; }else{ sump*=fi; f++; } } } if(sum<=2){ printf("2\n"); }else{ printf("1\n"); printf("%I64d\n",sump); } }
D - Quantity of Strings
思路:主要分为k>n,k=n,k<n的情况,见代码,wa掉这么多主要是前两种考虑出了问题
代码:
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cstdio> #include<vector> using namespace std; const long long int modd=1e9+7; int main(){ int n,m,k; scanf("%d %d %d",&n,&m,&k); __int64 sum=0; if(k<n){ if(k%2==0){ sum+=m; /* if(k!=2){ sum+=((m-1)*m)%modd; }*/ }else{ if(k==1){ __int64 num=1; for(int i=0;i<n;i++){ num=(num*m)%modd; num%=modd; } sum+=num; }else{ __int64 num=1; sum+=((m-1)*m)%modd; sum+=m; } } }else if(k==n){ if(k%2==0){ __int64 num=1; for(int i=0;i<n/2;i++){ num=(num*m)%modd; num%=modd; } sum+=num; }else{ __int64 num=1; for(int i=0;i<(n/2)+1;i++){ num=(num*m)%modd; num%=modd; } sum+=num; } }else{ __int64 num=1; for(int i=0;i<n;i++){ num=(num*m)%modd; num%=modd; } sum+=num; } printf("%I64d\n",sum); }
标签:__,people,int,Codeforces,Beta,int64,&&,include,107 来源: https://www.cnblogs.com/bonel/p/14772630.html