codeforces.com/contest/839/
来源:互联网 发布:js如何显示表单内容 编辑:程序博客网 时间:2024/06/08 00:11
http://codeforces.com/contest/839/
A
#include<stdio.h>#include<math.h>#include<string.h>#include<queue>#include<vector>#include<map>#include<algorithm>using namespace std;const int INF = 0x3f3f3f3f;int main(){ int n, k, y = 0; scanf("%d%d", &n, &k); int ans = -1; for(int i = 0; i < n; ++i) { int x; scanf("%d", &x); y += x; if(y > 8) k -= 8, y -= 8; else k -= y, y = 0; if(k <= 0 && ans == -1) ans = i + 1; } printf("%d\n", ans); return 0;}
B
有毒,跳过
C
树型dp?直接把问题分解到子问题`进行递归,直接dfs
#include<stdio.h>#include<math.h>#include<string.h>#include<queue>#include<vector>#include<map>#include<algorithm>using namespace std;const int MAXN = 100000 + 5;vector<int> G[MAXN];int n;double ans = 0.0;double dfs(int v, int fa) { int cnt = 0; double res = 0.0; for(int i = 0; i < G[v].size(); ++i) { if(G[v][i] != fa) ++cnt; } for(int i = 0; i < G[v].size(); ++i) { if(G[v][i] == fa) continue; res += dfs(G[v][i], v) + 1; } return cnt ? res / cnt : 0.0;}int main(){ scanf("%d", &n); for(int i = 1; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); G[x].push_back(y); G[y].push_back(x); } ans = dfs(1, 1); printf("%.15f\n", ans); return 0;}
D
可以参考 http://www.cnblogs.com/quintessence/p/7354412.html
不过感觉他推倒公式有个小bug,等式最左边应该是
#include<stdio.h>typedef long long LL;const int MOD = (int)1e9 + 7;const int MAXN = (int)1e6 + 5;int num[MAXN], res[MAXN], MA;int modpow(int a, int n) { int res = 1; while(n) { if(n & 1) res = 1LL * res * a % MOD; a = 1LL * a * a % MOD; n >>= 1; } return res;}void add(int x) { int i = 2; while(i * i < x) { if(x % i == 0) { ++num[i]; ++num[x / i]; } ++i; } if(i * i == x) ++num[i]; ++num[x];}int main(){ int n; scanf("%d", &n); for(int i = 0; i < n; ++i) { int x; scanf("%d", &x); add(x); if(x > MA) MA = x; } int ans = 0; for(int i = MA; i > 1; --i) { if(num[i] == 0) continue; res[i] = 1LL * num[i] * modpow(2, num[i] - 1) % MOD; for(int j = 2; i * j <= MA; ++j) { res[i] = (res[i] - res[i * j] + MOD) % MOD; } ans = (ans + 1LL * i * res[i]) % MOD; } printf("%d\n", ans); return 0;}
阅读全文
0 0
- codeforces.com/contest/839/
- codeforces.com/contest/793
- codeforces.com/contest/805
- codeforces.com/contest/897/
- http://codeforces.com/contest/34
- http://codeforces.com/contest/34
- http://codeforces.com/contest/6/problem/A
- http://codeforces.com/contest/7/problem/B
- http://codeforces.com/contest/7/problem/A
- http://codeforces.com/contest/1/problem/A
- http://codeforces.com/contest/1/problem/B
- http://codeforces.com/contest/263/problem/D
- http://codeforces.com/contest/276/problem/C
- codeforces.com/contest/325/problem/B
- http://codeforces.com/contest/366/problem/D
- http://codeforces.com/contest/368/problem/D
- http://codeforces.com/contest/432/problem/D
- http://codeforces.com/contest/366/problem/C之01背包
- PB中实现文件的拷贝与删除
- Gas Station问题及解法
- javascript 常用获取时间的方法
- 最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明
- springmvc http content-type
- codeforces.com/contest/839/
- 微服务开发的入门级框架Spring Boot详解(二)
- 4.3广义表
- Xilinx reVISION开搞!【reVISION】
- oom原理分析
- D
- 返回json数据中属性为null不参与序列化
- 本周计划
- 电话拨号器