Codeforces Round #340 (Div. 2) A B C D
来源:互联网 发布:网络运营商有哪些 编辑:程序博客网 时间:2024/05/02 06:13
http://codeforces.com/contest/617
A
尽量选择数值较大的
#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>using namespace std;int main(){ int x; while (cin>>x) { int cnt = 0; while (x >= 5) { x -= 5; cnt++; } while (x >= 4) { x -= 4; cnt++; } while (x >= 3) { x -= 3; cnt++; } while (x >= 2) { x -= 2; cnt++; } while (x >= 1) { x -= 1; cnt++; } cout << cnt << endl; } return 0;}
B
乘法计数原理
#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>using namespace std;int n;int a[110];long long b[110];int main(){ while (scanf("%d", &n) != EOF) { int ok = 0; for (int i = 1;i <= n;i++) { scanf("%d", &a[i]); if (a[i] == 1) ok = 1; } if ((n == 1 && a[1] == 0) || !ok) { printf("0\n"); continue; } memset(b, 1, sizeof(b)); int len = 0; int c1 = 0; int cnt = 0; for (int i = 1;i <= n;i++) { if (a[i] == 1) c1++; else if (a[i] == 0 && c1 != 0) cnt++; if (c1 > 1 && a[i] == 1) { b[len++] = cnt + 1; cnt = 0; } } long long ans = 1; for (int i = 0;i < len;i++) ans *= b[i]; printf("%lld\n", ans); } return 0;}
C
按与水池1距离大到小模拟
#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>using namespace std;struct Point{ Point() {} __int64 x, y;}p[10],q[2010];bool cmp(Point a,Point b){ __int64 t1 = (a.x - p[0].x) * (a.x - p[0].x) + (a.y - p[0].y) * (a.y - p[0].y); __int64 t2 = (b.x - p[0].x) * (b.x - p[0].x) + (b.y - p[0].y) * (b.y - p[0].y); __int64 t3 = (a.x - p[1].x) * (a.x - p[1].x) + (a.y - p[1].y) * (a.y - p[1].y); __int64 t4 = (b.x - p[1].x) * (b.x - p[1].x) + (b.y - p[1].y) * (b.y - p[1].y); if (t1 == t2) return t3 > t4; else return t1 > t2;} int main(){ int n; while (scanf("%d", &n) != EOF) { for (int i = 0;i < 2;i++) scanf("%I64d %I64d", &p[i].x, &p[i].y); for (int i = 0;i < n;i++) scanf("%I64d %I64d", &q[i].x, &q[i].y); sort(q, q + n, cmp); __int64 ans = 1e18, MAX = 0; for (int i = 0;i < n;i++) { ans = min(ans, MAX + (q[i].x - p[0].x) * (q[i].x - p[0].x) + (q[i].y - p[0].y)*(q[i].y - p[0].y)); MAX = max(MAX, (q[i].x - p[1].x) * (q[i].x - p[1].x) +(q[i].y - p[1].y)*(q[i].y - p[1].y)); } ans = min(ans, MAX); printf("%I64d\n" ,ans); } return 0;}
D
三点一线 - 1
两点一线 另一点不在两点之间区域 - 2
其他 - 3
#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>using namespace std;int x1, x2, x3, y11, y2, y3;bool is_two(int x1, int y1, int x2, int y2, int x3, int y3){ if (x1 == x2) { if (y3 <= min(y1, y2) || y3 >= max(y1, y2)) return true; return false; } if (x1 == x3) { if (y2 <= min(y1, y3) || y2 >= max(y1, y3)) return true; return false; } if (x3 == x2) { if (y1 <= min(y3, y2) || y1 >=max(y3, y2)) return true; return false; } if (y1 == y2) { if (x3 <= min(x1, x2) || x3 >= max(x1, x2)) return true; return false; } if (y1 == y3) { if (x2 <= min(x1, x3) || x2 >= max(x3, x1)) return true; return false; } if (y3 == y2) { if (x1 <= min(x3, x2) || x1 >= max(x3, x2)) return true; return false; } return false;}int main(){ while (cin >> x1 >> y11 >> x2 >> y2 >> x3 >> y3) { int ans; if (x1 == x2 && x1 == x3) ans = 1; else if (y11 == y2 && y2 == y3) ans = 1; else if (is_two(x1, y11, x2, y2, x3, y3)) { ans = 2; } else ans = 3; cout << ans << endl; } return 0;}
0 0
- Codeforces Round #340 (Div. 2) A B C D
- Codeforces Round #340 (Div. 2) (A,B,C,D)
- Codeforces Round #179 (Div. 2)A、B、C、D
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #211 (Div. 2)(A,B,C,D)
- Codeforces Round #220 (Div. 2)(A,B,C,D)
- Codeforces Round #231 (Div. 2)A, B, C, D
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
- Codeforces Round #246 (Div. 2) A,B,C,D
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #259 (Div. 2) A/B/C/D
- Codeforces Round #257 (Div. 2) A/B/C/D
- Codeforces Round #256 (Div. 2) A/B/C/D
- Codeforces Round #262 (Div. 2)-A,B,C,D
- Codeforces Round #263 (Div. 2) A,B,C,D,E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- Codeforces Round #276 (Div. 2) A B C D
- uva11384 - Help is needed for Dexter (递归)
- fiddler是程序抓包必备软件之一,分享一个关于fiddler的技术博客
- Event-Driven Data Management for Microservices
- Hibernate高级技术
- 【可持久化线段树】【主席树】[HDU4417]Super Mario
- Codeforces Round #340 (Div. 2) A B C D
- angularjs 复制
- Linux 搭建LAMP 源码编译详细文档
- 空间滤波&频域滤波(2)
- 代码:用二分法求2x^3-4x^2+3x-6=0在-10~10之间的根(函数)
- 我是如何入门html和php的
- STM32 堆和栈的学习
- 读书笔记 精通CSS 高级Web标准解决方案(第2版)1~3章
- android listview优化:滑动时颜色错乱问题