codeforces补题:979
Posted pandaking
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces补题:979相关的知识,希望对你有一定的参考价值。
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++){ 14 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 ",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 "); 39 }else{ 40 if(mxans==ansl[1]){ 41 printf("Kuro ");return 0; 42 }else if(mxans==ansl[2]){ 43 printf("Shiro ");return 0; 44 }else{ 45 printf("Katie ");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 "); 86 87 if (v[0] == mx) printf("Kuro "); 88 if (v[1] == mx) printf("Shiro "); 89 if (v[2] == mx) printf("Katie "); 90 return 0; 91 }
这一场因为其他题都没看,所以就暂时鸽了
以上是关于codeforces补题:979的主要内容,如果未能解决你的问题,请参考以下文章
codeforces 979C Kuro and Walking Route
Codeforces Round #627 (Div. 3) 补题
Codeforces Round #634 (Div. 3) 补题
Codeforces Round #482 (Div. 2) C Kuro and Walking Route(dfs)979C