Codeforces Round #346 (Div. 2) ABCDE
2016-04-03 17:10
295 查看
题目:http://codeforces.com/contest/659/problems
A:
B:
C:
D:
E:
A:
#include <iostream> #include <string> using namespace std; int n, a, b; int main() { while (cin >> n >> a >> b) { int ans; ans = (a + b + n * 1000) % (n); if (ans == 0) ans = n; cout << ans << endl; } return 0; }
B:
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; vector <pair<int, string>> a[10010]; int n, m; int main() { while (cin >> n >> m) { string tmp; int num, val; for (int i = 1;i <= n;i++) { cin >> tmp >> num >> val; num--; val = -val; a[num].push_back(make_pair(val, tmp)); } for (int i = 0;i < m;i++) { sort(a[i].begin(), a[i].end()); if (a[i].size() > 2 && a[i][1].first == a[i][2].first) puts("?"); else cout << a[i][0].second <<" "<< a[i][1].second << endl; } } return 0; }
C:
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> using namespace std; int n, m; set<int> S; vector<int> ans; int main() { while (cin >> n >> m) { ans.clear(); S.clear(); set<int>::iterator pos; vector<int>::iterator it; int tmp; for (int i = 1;i <= n;i++) { cin >> tmp; S.insert(tmp); } tmp = 1; while (m) { if (m < tmp) break; if (S.count(tmp) == 0) { m -= tmp; ans.push_back(tmp); S.insert(tmp); tmp++; } else tmp++; } cout << ans.size() << endl; for (it = ans.begin();it != ans.end();it++) cout << *it << " "; cout << endl; } return 0; }
D:
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> using namespace std; int n; struct { int x, y; }a[1010]; int main() { while (scanf("%d", &n) != EOF) { memset(b, 0, sizeof(b)); for (int i = 0;i <= n;i++) { scanf("%d %d", &a[i].x, &a[i].y); } int ans = 0; for (int i = 0;i < n;i++) { int t1 = i + 1; int t2 = i + 2; if (t2 == n + 1) t2 = 0; if (a[i].x < a[i + 1].x && a[i].y == a[i + 1].y)//右 { if (a[t1].x == a[t2].x && a[t1].y < a[t2].y)//↑ ans++; } else if (a[i].x > a[i + 1].x && a[i].y == a[i + 1].y)//左 { if (a[t1].x == a[t2].x && a[t1].y > a[t2].y)//下 ans++; } else if (a[i].x == a[i + 1].x && a[i].y < a[i + 1].y)//上 { if (a[t1].x > a[t2].x && a[t1].y == a[t2].y)//左 ans++; } else if (a[i].x == a[i + 1].x && a[i].y > a[i + 1].y)//下 { if (a[t1].x < a[t2].x && a[t1].y == a[t2].y)//右 ans++; } } printf("%d\n", ans); } return 0; }
E:
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> using namespace std; const int MAXN = 200010; vector<int> g[MAXN]; int n, m, nnode, nedge; int vis[MAXN]; void dfs(int u) { vis[u] = 1; nnode++; for (int i = 0;i < g[u].size();i++) { int v = g[u][i]; nedge++; if (!vis[v]) dfs(v); } } int main() { while (scanf("%d %d", &n, &m) != EOF) { memset(vis, 0, sizeof vis); for (int i = 0;i <= n;i++) g[i].clear(); int u, v; for (int i = 1;i <= m;i++) { scanf("%d %d", &u, &v); g[u].push_back(v); g[v].push_back(u); } int ans = 0; for (int i = 1;i <= n;i++) { if (!vis[i]) { nnode = nedge = 0; dfs(i); if (nedge / 2 == nnode - 1) ans++; } } printf("%d\n", ans); } return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query