2012 Asia Chengdu Regional Contest - Gemini Boy - ACM之路~
2012 Asia Chengdu Regional Contest
A题(HDU 4464):无意义的题。。就贴个代码吧。
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int maxn = 10010; int n, cas; char ch[maxn]; int main() { cas = 0; while (~scanf("%d", &n)) { int ans = 0; for (int i = 0; i < n; i++) { scanf("%s", ch); int len = strlen(ch); int sum = 0; for (int i = 0; i < len; i++) { sum += (int)ch[i]; } if (ans < sum) ans = sum; } printf("Case %d: %d\n", ++cas, ans); } return 0; }
B题(HDU 4465):这题是道求期望的题,还算比较简单。公式很容易得到:
但是因为组合数比较大,不能直接算。为了保证精度,可以先求log,然后再用乘方,算回来。
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> using namespace std; int n, cas = 0; double p; int main() { while (~scanf("%d %lf", &n, &p)) { printf("Case %d: ", ++cas); double q = 1 - p; if (fabs(p) < 1e-10 || fabs(q)<1e-10) { printf("%.6lf\n", 1.0 * n); continue; } double tmp = (n + 1) * log(p); double tem = (n + 1) * log(q); double ans = 0, t = 0, tt = 0, ttt = 0; for (int i = n + 1; i <= n + n; i++) { tt = t + tmp + (i-1-n) * log(q) + log(1.0+n+n-i); ttt = t + tem + (i-1-n) * log(p) + log(1.0+n+n-i); ans += exp(tt) + exp(ttt); t += log(1.0*i) - log(1.0*i-n); } printf("%.6lf\n", ans); } return 0; }