标签:style blog for 2014 div c++ amp size
A.水题,输出图形
B.水题
C.概率题
/* m, n 最大数为k的总数为 k^n - (k-1)^n 所以最大数为k的期望为 (k^n - (k-1)^n) / (m^n) */ #include<bits/stdc++.h> using namespace std; int main() { int n, m; int i, j; scanf("%d%d", &m, &n); double ans = m; for(i=1; i<=m-1; ++i) { double x = i*1.0/m; ans = ans - pow(x, n); } printf("%.12f\n", ans); return 0; }
D. 状态压缩DP
#include<bits/stdc++.h> using namespace std; int pri[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int dp[105][1<<16]; int p[105][1<<16]; int mask[60]; //mask[i]已二进制形式表示是否含有pri[j] int a[105]; int main() { int n, i, j, k; for(i=1; i<60; ++i) for(j=0; j<16; ++j) if(i%pri[j]==0) mask[i] |= 1<<j; scanf("%d", &n); for(i=1; i<=n; ++i) scanf("%d", &a[i]); memset(dp, 0x3f, sizeof dp ); dp[0][0] = 0; for(i=1; i<=n; ++i) { for(j=0; j< (1<<16); ++j) for(k=1; k<60; ++k) if( (mask[k]&j)==0) { if(dp[i][j|mask[k]]>dp[i-1][j] + abs(a[i]-k)) { dp[i][j|mask[k]] = dp[i-1][j] + abs(a[i]-k); p[i][j|mask[k]] = k; } } } vector<int> ans; for(int i=n, m=min_element(dp[i], dp[i]+(1<<16)) - dp[i]; i>0; m ^= mask[p[i][m]], --i) ans.push_back(p[i][m]); for(i=1; i<=n; ++i) printf("%d ", ans[n-i]); return 0; }
Codeforces Round #246 (Div. 2) A,B,C,D,布布扣,bubuko.com
Codeforces Round #246 (Div. 2) A,B,C,D
标签:style blog for 2014 div c++ amp size
原文地址:http://blog.csdn.net/yew1eb/article/details/38353213