codeforces補題:979
阿新 • • 發佈:2018-10-04
color std printf cti sse amp queue stdio.h bad
codeforces 979b:::
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e5+100; 4 int n; 5 char s[maxn]; 6 int num[100];//Kuro Shiro Katie 7 int ansl[5]; 8 9 int solve(){ 10 scanf("%s",s+1); 11 memset(num,0,sizeof(num)); 12 int len=strlen(s+1); 13 for(int i=1;i<=len;i++){View Code14 if(s[i]>=‘A‘&&s[i]<=‘Z‘) num[s[i]-‘A‘+1]++; 15 else num[s[i]-‘a‘+27]++; 16 } 17 int mx=0,m=n; 18 for(int i=1;i<=52;i++) mx=max(num[i],mx); 19 20 if(mx+m<=len) return mx+m; 21 else{ 22 if(mx==len){ 23 if(m==1) return len-1; 24 else return len; 25 }else{ 26 return len; 27 } 28 } 29 } 30 int main(){ 31 scanf("%d",&n); 32 ansl[1]=solve(); 33 ansl[2]=solve(); 34 ansl[3]=solve(); 35 int mxans=max(ansl[1],max(ansl[2],ansl[3])); 36 // for(int i=1;i<=3;i++) printf("%d\n",ansl[i]);37 if((mxans==ansl[1]&&mxans==ansl[2])||(mxans==ansl[2]&&mxans==ansl[3])||(mxans==ansl[1]&&mxans==ansl[3])){ 38 printf("Draw\n"); 39 }else{ 40 if(mxans==ansl[1]){ 41 printf("Kuro\n");return 0; 42 }else if(mxans==ansl[2]){ 43 printf("Shiro\n");return 0; 44 }else{ 45 printf("Katie\n");return 0; 46 } 47 } 48 return 0; 49 }
看了一個紅黑大神的代碼,感覺差距不知道大到哪兒去了,接下來貼一下這個大神的寫法
1 #include <stdio.h> 2 #include <algorithm> 3 #include <assert.h> 4 #include <bitset> 5 #include <cmath> 6 #include <complex> 7 #include <deque> 8 #include <functional> 9 #include <iostream> 10 #include <limits.h> 11 #include <map> 12 #include <math.h> 13 #include <queue> 14 #include <set> 15 #include <stdlib.h> 16 #include <string.h> 17 #include <string> 18 #include <time.h> 19 //#include <unordered_map> 20 //#include <unordered_set> 21 #include <vector> 22 23 #pragma warning(disable:4996) 24 #pragma comment(linker, "/STACK:336777216") 25 26 using namespace std; 27 28 #define mp make_pair 29 #define all(x) (x).begin(), (x).end() 30 31 //typedef tuple<int, int, int> t3; 32 typedef long long ll; 33 typedef unsigned long long ull; 34 typedef double db; 35 typedef long double ldb; 36 typedef pair <int, int> pii; 37 typedef pair <ll, ll> pll; 38 typedef pair <db, db> pdd; 39 40 int IT_MAX = 1 << 18; // segment tree size 41 const ll MOD = 1000000007; 42 const int INF = 0x3f3f3f3f; // memset(dp, 0x3f, sizeof(dp)), 2*INF < INT_MAX 43 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; 44 const db PI = acos(-1); 45 const db ERR = 1e-10; // double EPS 46 47 char u[100050]; 48 49 int cnt[52]; 50 int ch(char c) { 51 if (c >= ‘a‘ && c <= ‘z‘) return c - ‘a‘; 52 return c - ‘A‘ + 26; 53 } 54 int getans(int N) { 55 scanf("%s", u); 56 int i, L = strlen(u); 57 for (i = 0; i < 52; i++) cnt[i] = 0; 58 for (i = 0; i < L; i++) cnt[ch(u[i])]++; 59 60 if (L == 1) return 1; 61 62 int mx = 0; 63 for (i = 0; i < 52; i++) mx = max(mx, cnt[i]); 64 65 if (mx == L) { 66 if (N == 1) return mx - 1; 67 else return mx; 68 } 69 70 return min(L, mx + N); 71 } 72 int main() { 73 int N, i; 74 scanf("%d", &N); 75 76 int v[3]; 77 v[0] = getans(N); 78 v[1] = getans(N); 79 v[2] = getans(N); 80 81 int mx = max(max(v[0], v[1]), v[2]); 82 83 int c = 0; 84 for (i = 0; i < 3; i++) if (v[i] == mx) c++; 85 if (c >= 2) return !printf("Draw\n"); 86 87 if (v[0] == mx) printf("Kuro\n"); 88 if (v[1] == mx) printf("Shiro\n"); 89 if (v[2] == mx) printf("Katie\n"); 90 return 0; 91 }View Code
這一場因為其他題都沒看,所以就暫時鴿了
codeforces補題:979