Codeforces Round #345 (Div. 2)题解
来源:互联网 发布:奥凯航空的航线网络 编辑:程序博客网 时间:2024/06/05 14:33
A. Joysticks
传送门
模拟就行了,
每次都先给电量少的充电,直到另一个的电量不足以多使用1minute,
#include <bits/stdc++.h>#define ll long long#define N 100using namespace std;int main(){#ifndef ONLINE_JUDGE// freopen("1.txt", "r", stdin);#endif int i, j, k; int a1, a2, ans = 0, t; cin >> a1 >> a2; while(a1 > 0 && a2 > 0) { if (a1 < a2) swap(a1, a2); t = a1/2; if (a1 == 2) { ans++; break; } if (a1&1) { a2 += t; a1 = 1; } else { t--; a1 = 2; a2 += t; } ans += t; if (a1 < 2 && a2 < 2) break; } cout << ans; return 0;}
B. Beautiful Paintings
传送门
set详解
#include <bits/stdc++.h>#define ll long long#define N 1010using namespace std;set<int> s[N];int main(){#ifndef ONLINE_JUDGE// freopen("1.txt", "r", stdin);#endif int i, j, k, t; int n, ans; for (i = 0; i < 1000; i++) s[i].clear(); cin >> n; for (i = 0; i < n; i++) { cin >> t; for (j = 0; j < 1000; j++) { if (s[j].find(t) == s[j].end()) { s[j].insert(t); break; } } } ans = 0; for (i = 0; i < 1000; i++) { t = s[i].size(); ans += t?t-1:0; } cout << ans; return 0;}
C. Watchmen
传送门
map详情
这道题竟然在终测的时候爆int了 /(ㄒoㄒ)/~~
map<int, int>应该改成map<long long, long long>,这样直接就AC了
这道题的意思就是找有多少对坐标对满足曼和顿距离和欧几里得距离相等,满足这种条件的坐标对都在同一条直线上。
用map计算就行了
#include <bits/stdc++.h>#define ll long long#define N 200010using namespace std;struct point{ int x, y;}node[N];bool cmp_x(point a, point b){ if (a.x == b.x) return a.y < b.y; return a.x < b.x;}map<ll,ll> mx, my;int main(){#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif int i, j, k, n, xx, yy; ll ans = 0, t, tmp; map<ll,ll>::iterator it; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &node[i].x, &node[i].y); if (mx.find(node[i].x) == mx.end()) { mx.insert(pair<ll,ll>(node[i].x, 1)); } else { mx[node[i].x]++; } if (my.find(node[i].y) == my.end()) { my.insert(pair<ll,ll>(node[i].y, 1)); } else { my[node[i].y]++; } } for (it = mx.begin(); it != mx.end(); it++) ans += (it->second)*((it->second)-1)/2; for (it = my.begin(); it != my.end(); it++) ans += it->second*(it->second-1)/2; sort(node, node+n, cmp_x); t = 1; for (i = 1; i < n; i++) { if (node[i].x == node[i-1].x && node[i].y == node[i-1].y) { t++; } else { ans -= t*(t-1)/2; t = 1; } } ans -= t*(t-1)/2; cout << ans; return 0;}
D. Image Preview
传送门
#include <bits/stdc++.h>#define ll long long#define N 500010using namespace std;int n, a, b, t;int num[N]; //前i个数有多少需要旋转的 int is[N];int main(){#ifndef ONLINE_JUDGE// freopen("1.txt", "r", stdin);#endif char c; scanf("%d%d%d%d", &n, &a, &b, &t); getchar(); for (int i = 0; i < n; i++) { scanf("%c", &c); is[i] = (c == 'w'); num[i] = is[i]; if (i) num[i] += num[i-1]; } if (is[0]*b+1 > t) { cout << 0; return 0; } int l = 0, sum = 0; //从第一个想第n个开始看 for (; ; ) { if (is[l]) sum += b; sum++; if (sum > t) break; sum += a; l = (l-1+n)%n; if (!l) break; //全部都已经看完 }//如果一直向右看,可以看到l张,共看n-1-l+1张照片 if (!l) { cout << n; return 0; } int ws, ans = n-1-l+1;//ws为需要旋转的照片的数量 for (int r = 1; r < n; r++) { ws = num[r];//0到r里面需要翻转的数量 ws += num[n-1] - num[l];//l到n-1里面需要翻转的数量 while(l && ws*b+r+1+(n-1-l)+a*(r+(n-1-l))+a*min(r, n-1-l) > t) { l = (l+1)%n; ws = num[r]; ws += num[n-1]-num[l]; } if (!l) break; ans = max(ans, r+1+n-1-l); } cout << ans; return 0;}
0 0
- Codeforces Round #345 (Div. 2)题解
- 【codeforces】Codeforces Round #276 (Div. 2) 题解
- 【codeforces】Codeforces Round #277 (Div. 2) 题解
- 【codeforces】Codeforces Round #279 (Div. 2) 题解
- 【codeforces】Codeforces Round #283 (Div. 2) 【题解】
- 【codeforces】Codeforces Round #291 (Div. 2) 题解
- Codeforces Round #131 (Div. 2) 完整题解
- Codeforces Round #135 (Div. 2)题解
- Codeforces Round #192 (Div. 2) 题解报告
- Codeforces Round #194 (Div. 2) 题解
- Codeforces Round #216 (Div. 2)部分题解
- Codeforces Round #226 (Div. 2) 题解
- Codeforces Round #177 (Div. 2) 题解
- Codeforces Round #FF (Div. 2) 题解
- Codeforces Round #256 (Div. 2) 题解
- Codeforces Round #257 (Div. 2) 题解
- Codeforces Round #259 (Div. 2) 题解
- Codeforces Round #260 (Div. 2) 题解
- pat1008:数组元素循环右移问题
- Activity和Service的启动
- 小东西
- 15、vs2010实践中遇到问题汇总
- obj文件
- Codeforces Round #345 (Div. 2)题解
- Allen OpenCart 多功能自适应主题模板 ABC-0705
- shareSDK 快速集成
- OpenGL 库函数汇总
- Java二维数组
- /data/data/和手机拍照
- MachineLearning in Action_KNN
- kafak、flume、elasticsearch
- 使用timer方法生成一个定时器,每隔一段时间输出一个随机数