首页 > 代码库 > Codeforces #105 DIV2 ABCDE
Codeforces #105 DIV2 ABCDE
开始按照顺序刷刷以前的CF。
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}int a[4],d;int main(){ while (cin>>a[0]>>a[1]>>a[2]>>a[3]>>d) { int ans = 0; for (int i = 1; i <= d; i++) { for (int j = 0; j < 4; j++) if (i % a[j] == 0) { ans ++; break; } } cout<<ans<<endl; } return 0;}
B贡献无数发WA。注意相遇的条件 直接double处理就可以。一直以为按照相应直接直接跳跃相应距离 直接int处理
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}int vp,vd,t,f,c;int pos[1010];int main(){ while (cin>>vp>>vd>>t>>f>>c) { if (vp >= vd) {puts("0");continue;} int thev = vd - vp; double pospri = vp * t;int ans = 0; while (pospri < c) { double ti = pospri / (double)thev; if ((double) vd * ti >= c) break; ans ++; pospri = pospri + f * vp +(double) 2 * ti * vp; // printf("%d\n",pospri); if (pospri >= c) break; } cout <<ans <<endl; } return 0;}
C 坑点比较多。注意b等于0的情况
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}int n,a,b;int num[110];int main(){ while (cin >> n >> a >> b) { if (a > n || b > n){ puts("-1");continue;} if (a > 0 && b == 0) { if (n - a < 2) {puts("-1");continue;} else { printf("1 1 "); for (int i = 1 ,k = 2,j = 3; j <= n && i <= a ; k++,i++) printf("%d ",k); for (int i = a + 3; i <= n; i++) printf("%d ",a + 1); puts(""); } continue; } for (int i = 0; i < 110; i++) num[i] = 1; int cas = 1; int sum = 1; for (int i = 2; i <= b + 1; i++) { num[i] = sum + cas; sum += num[i]; } cas = 1; for (int i = b + 2; i <= a + b + 1;i ++) { num[i] = num[i - 1] + cas; } for (int i = 1; i <= n; i++) if (i == 1) cout << num[i]; else cout << ‘ ‘ << num[i]; puts(""); } return 0;}
D DP
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}int w,b;double dp[1010][1010];void init(){ for (int i = 0; i < 1001; i++) { dp[i][0] = 1.0; dp[0][i] = 0.0; } for (int w = 1; w < 1001; w++) for (int b = 1; b < 1001; b++) { dp[w][b] += 1.0 * w / (w + b); if (b >= 3) dp[w][b] += dp[w][b - 3] * 1.0 * b / (w + b) * 1.0 * (b - 1) / (w + b - 1) * 1.0 * (b - 2) / (w + b - 2); if (b >= 2) dp[w][b] += dp[w - 1][b - 2] * 1.0 * b / (w + b) * 1.0 * (b - 1) / (w + b - 1) * w / (w + b - 2); }}int main(){ init(); while (scanf("%d%d",&w,&b) != EOF) printf("%.9lf\n",dp[w][b]); return 0;}
E DP预处理+DP
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}#define MAXN 110#define MAXD 10010int sum[MAXN][MAXD],dp[MAXN][MAXD],res[MAXN][MAXD];int N,M;int num[MAXN];int main(){ while (scanf("%d%d",&N,&M) != EOF) { memset(dp,0,sizeof(dp)); memset(res,0,sizeof(res)); for (int i = 1; i <= N; i++) { scanf("%d",&num[i]); sum[i][0] = 0; for (int j = 1; j <= num[i];j++) { int tmp; scanf("%d",&tmp); sum[i][j] = sum[i][j - 1] + tmp; } res[i][0] = 0; for (int j = 1; j <= num[i]; j++) for (int k = 0; k <= j; k++) res[i][j] = max(res[i][j],sum[i][k] + sum[i][num[i]] - sum[i][num[i] - (j - k)]); } for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) for (int k = 0; k <= num[i] && k <= j; k++) dp[i][j] = max(dp[i][j],max(dp[i - 1][j],dp[i - 1][j - k] + res[i][k])); printf("%d\n",dp[N][M]); } return 0;}
Codeforces #105 DIV2 ABCDE
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。