Codeforces Round #187 (Div. 2)
来源:互联网 发布:h5微场景页面源码 编辑:程序博客网 时间:2024/04/29 13:43
Problem set: http://codeforces.com/contest/315
Official solution:
Problem A: straightforward
#include <iostream>using namespace std;int main() { int n, a[100], b[100], v[100] = {0}; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; if (b[i] == a[j]) v[j] = 1; } } int ans = 0; for (int i = 0; i < n; ++i) if (!v[i]) ++ans; cout << ans << endl; return 0;}
Problem B: store sum of update, use differences of two sum to get a partial sum in a range
#include <iostream>#include <vector>using namespace std;int main() { int n, m; cin >> n >> m; vector<int> a(n), reset(n, -1); for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> inc(m, 0); for (int i = 0; i < m; ++i) { if (i > 0) inc[i] = inc[i - 1]; int t; cin >> t; if (t == 1) { int v, x; cin >> v >> x; a[v - 1] = x; reset[v - 1] = i; } else if (t == 2) { int y; cin >> y; inc[i] += y; } else { int q; cin >> q; cout << a[q - 1] + inc[i] - (reset[q - 1] == -1 ? 0 : inc[reset[q - 1]]) << '\n'; } } return 0;}
Problem C: use doubly linked list as data structure; add the sum in linear time
#include <iostream>using namespace std;int a[200001];int head, nxt[200001], pre[200001];int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; pre[i] = i - 1; if (i < n) nxt[i] = i + 1; } head = 1; int m = n; while (true) { bool flag = true; double d = 0; int i = 0; int j = head; while (j) { ++i; if (j != head) d += (a[pre[j]] * double(i - 2)); if (flag && d - double(m - i) * a[j] * (i - 1) + 1e-6 < k) { cout << j << '\n'; flag = false; --m; //if (head == j) head = nxt[j]; pre[nxt[j]] = pre[j]; nxt[pre[j]] = nxt[j]; break; } j = nxt[j]; } if (flag) break; } return 0;}
- Codeforces Round #187 (Div. 2)
- codeforces Round # 187(Div.2) D
- Codeforces Round #187 (Div. 2) 总结
- Codeforces Round #187 DIV 1
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #125 (Div. 2)
- uestc oj 1828 中二少女与字符串
- oracle 11g PL/SQL Programming学习十
- uestc oj 1223 Islands
- JIRA 6.0.1 (ZIP Archive)最新破解方法,绝对可用
- MFC 基础知识:主对话框与子对话框(一)
- Codeforces Round #187 (Div. 2)
- Deep Learning(深度学习)学习笔记整理系列
- 迄今见过的最好的职业规划文章
- MFC 基础知识:主对话框与子对话框(二)
- http协议和web应用有状态和无状态辨析
- Content脚本与扩展的其他页面脚本的消息传递
- 高效学习有秘方
- php实战第十九天
- RECoding Today