题目传送:BestCoder Round #41
A、ZCC loves straight flush
思路:简单题,不过刚开始没看清题,wa了好几次,然后才发现输入不连续也可以,就是说每个同一花色的牌都可以放在一块,不用在意输入顺序,感觉这里题目应该说清楚点好些
AC代码(略挫,比赛时写的都比较乱):
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <deque> #include <cctype> #define LL long long #define INF 0x7fffffff using namespace std; char a[5][5]; int fun(int *p, int n) { sort(p, p + n); int ret = 1; if(p[0] != 1) { for(int i = 1; i <= 9; i ++) { int cur = 0; for(int j = 0; j < n; j ++) { if(p[j] <= i + 4 && p[j] >= i) { cur ++; } ret = max(ret, cur); } } } else if(p[0] == 1) { for(int i = 1; i <= 10; i ++) { int cur = 0; for(int j = 0; j < n; j ++) { if(p[j] <= i + 4 && p[j] >= i) { cur ++; } } if(i == 10) cur ++; ret = max(ret, cur); } } return ret; } int main() { int T; scanf("%d", &T); while(T --) { scanf("%s %s %s %s %s", a[0], a[1], a[2], a[3], a[4]); int cur = 1; int num[5]; memset(num, 0, sizeof(num)); for(int i = 0; i < 5; i ++) { int len = strlen(a[i]); for(int j = 1; j < len; j ++) { num[i] = num[i] * 10 + a[i][j] - '0'; } } /*for(int i = 0; i < 5; i ++) { cout << num[i] << " "; } cout << endl;*/ int A[5], B[5], C[5], D[5]; int an = 0, bn = 0, cn = 0, dn = 0; for(int i = 0; i < 5; i++) { if(a[i][0] == 'A') A[an ++] = num[i]; else if(a[i][0] == 'B') B[bn ++] = num[i]; else if(a[i][0] == 'C') C[cn ++] = num[i]; else if(a[i][0] == 'D') D[dn ++] = num[i]; } int ans = 1; ans = max(ans, fun(A, an)); ans = max(ans, fun(B, bn)); ans = max(ans, fun(C, cn)); ans = max(ans, fun(D, dn)); printf("%d\n", 5 - ans); } return 0; }
B、ZCC loves strings
思路:找规律,简单博弈,但是坑点较多,总共有Cn取2中情况,然后Miss G赢得情况有奇数和偶数凑一块的时候,还有选择相同字符串的时候,然后特判一下ans是否为0,再取个gcd,记得用longlong,会爆int
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <string> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <deque> #include <cctype> #define LL long long #define INF 0x7fffffff using namespace std; int a[200005]; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); } int main() { ios::sync_with_stdio(false); int T, n; scanf("%d", &T); while(T --) { scanf("%d", &n); string tmp; LL ji = 0, ou = 0; map<string, int> mmp; LL jia = 0; for(int i = 0; i < n; i ++) { cin >> tmp; if(mmp.find(tmp) != mmp.end()) { jia += mmp[tmp]; mmp[tmp] ++; } else mmp[tmp] = 1; a[i] = tmp.length(); if(a[i] & 1) ji ++; else ou ++; } LL ans = ji * ou; LL sum = n * (n - 1) / 2; ans += jia; if(ans == 0) { printf("0/1\n"); continue; } LL gg = gcd(ans, sum); ans /= gg; sum /= gg; cout << ans << '/' << sum << endl; } return 0; }
好了,这是我搞算法半年多以来打得稍微好一点的比赛了,虽然前几十分钟在乱搞,但是后来hack环节还是蛮激动的,好感人啊,BC紫名了,虽然质量不是太高,但是还是挺激动地,静静地等着我CF紫名,先贴个图片纪念纪念
原文地址:http://blog.csdn.net/u014355480/article/details/45772843