Codeforces 402A 402B 402C 402D
来源:互联网 发布:怎么可以看网络电视 编辑:程序博客网 时间:2024/05/29 16:17
402A 直接暴力
#include <cstdio>#include <cstdlib>#include <cmath>#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <sstream>#include <string>#include <cstring>#include <algorithm>#include <iostream>#define maxn 2010#define INF 0x7fffffff#define inf 10000000#define MOD 1000000007#define ull unsigned long long#define ll long longusing namespace std;int main(){ int k, a, b, v; scanf("%d%d%d%d", &k, &a, &b, &v); int ans = 0; while(a > 0) { ans ++; if(b >= k-1) { a -= k*v; b = b-k+1; } else { a -= (b+1)*v; b = 0; } } printf("%d\n", ans); return 0;}
402B
修改尽量少的数字使数列成为公差为k的等差数列 (但是不能有负数)
#include <cstdio>#include <cstdlib>#include <cmath>#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <sstream>#include <string>#include <cstring>#include <algorithm>#include <iostream>#define maxn 2010#define INF 0x7fffffff#define inf 10000000#define MOD 1000000007#define ull unsigned long long#define ll long longusing namespace std;int num[1010], ans[1010], tem[1010];int main(){ int n, k; memset(ans, 0, sizeof(ans)); scanf("%d%d", &n, &k); for(int i = 0; i < n; ++ i) { scanf("%d", &num[i]); tem[i] = num[i] - i*k; } sort(tem, tem+n); int j = 0; while(tem[j] <= 0) ++ j; int now = tem[j], _max = 0, cnt = 0, cc = tem[j]; for(int i = j; i < n; ++ i) { if(now == tem[i]) ++ cnt; else { if(cnt > _max) { _max = cnt; cc = now; } now = tem[i]; cnt = 1; } } if(cnt > _max) { _max = cnt; cc = now; } printf("%d\n", n-_max); for(int i = 0; i < n; ++ i) { if(cc+i*k > num[i]) printf("+ %d %d\n", i+1, cc+i*k-num[i]); if(cc+i*k < num[i]) printf("- %d %d\n", i+1, num[i]-cc-i*k); } return 0;}
402C 猜了一下 直接枚举一个最有可能的
#include <cstdio>#include <cstdlib>#include <cmath>#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <sstream>#include <string>#include <cstring>#include <algorithm>#include <iostream>#define maxn 2010#define INF 0x7fffffff#define inf 10000000#define MOD 1000000007#define ull unsigned long long#define ll long longusing namespace std;int main(){ int t, n, p; scanf("%d", &t); while(t --) { scanf("%d%d", &n, &p); int now = 2*n+p, st = 1, k = 1; while(now--) { printf("%d %d\n", st, (st+k)%n == 0 ? n : (st+k)%n); ++ st; if(st == n+1) { st = 1; ++ k; } } } return 0;}
402D
数学加贪心
#include <cstdio>#include <cstdlib>#include <cmath>#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <sstream>#include <string>#include <cstring>#include <algorithm>#include <iostream>#define maxn 2010#define INF 0x7fffffff#define inf 10000000#define MOD 1000000007#define ull unsigned long long#define ll long longusing namespace std;int a[5010], cou[5010], pp[100000], m;bool vis[100000];struct node{ int b[5050]; bool find(int x) { for(int i = 0; i < m; ++ i) if(b[i] == x) return true; return false; }};node prime;int fi_pri(){ int j = 0; memset(vis, 1, sizeof(vis)); for(ll i = 2; i < 100000; ++ i) if(vis[i]) { pp[j++] = i; for(ll j = i*i; j < 100000; j += i) vis[j] = false; } return j;}int gcd(int r, int l){ return l == 0 ? r : gcd(l, r%l);}bool can(int i, int j){ int ans = 0; for(int k = 0; k < j; ++ k) if((i % pp[k] == 0) && (prime.find(pp[k]))) while(i % pp[k] == 0) { -- ans; i /= pp[k]; } else while(i % pp[k] == 0) { ++ ans; i /= pp[k]; } if(prime.find(i)) --ans; if(ans < 0) return true; return false;}int f(int s, int j){ if(s == 1) return 0; int i; for(i = 0; i < j; ++ i) if(s%pp[i] == 0) break; if(i != j && prime.find(pp[i])) return f(s/pp[i], j) -1; if(i != j) return f(s/pp[i], j) +1; if(prime.find(s)) return -1; return 1;}int main(){ int asd = fi_pri(); int n, g; scanf("%d%d", &n, &m); scanf("%d", &a[0]); g = cou[0] = a[0]; for(int i = 1; i < n; ++ i) { scanf("%d", &a[i]); g = cou[i] = gcd(g, a[i]); } for(int i = 0; i < m; ++ i) scanf("%d", &prime.b[i]); for(int i = n-1; i >= 0; -- i) if(can(cou[i], asd)) for(int j = 0; j <= i; ++ j) { a[j] /= cou[i]; cou[j] /= cou[i]; } int ans = 0; for(int i = 0; i < n; ++ i) ans += f(a[i], asd); printf("%d\n", ans); return 0;}
0 0
- Codeforces 402A 402B 402C 402D
- Codeforces Round #402 (Div. 2) A+B+C+D
- 【Codeforces Round #402 (Div. 2) 】(A,B,C,D )
- Codeforces Round #402 (Div. 2)A.B.C.D
- codeforces 239 (div2) A B C D
- codeforces 208(div2) A+B+C+D
- codeforces 445 A、B、C、D
- codeforces 250 div2 A B C D
- CodeForces 412(A,B,C,D,E)
- Codeforces Round #351 A B C D
- codeforces 723 A,B,C,D
- Codeforces Round #377 A.B.C.D
- codeforces 817 A B C D
- codeforces 402B - Trees in a Row
- codeforces 402B Trees in a Row
- Codeforces Round #402 (Div. 2) A+B
- Codeforces Educational Round #18(Codeforces 792 A B C D)
- Codeforces-Educational Codeforces Round 32-(A,B,C,D)
- 平衡二叉树最清楚的文章
- 这个坑,你遇到过吗?关于UIView上添加一个手势,导致子视图为UIButton的无法响应的问题
- C#中Dictionary的用法
- CI项目设计权限检查
- android数据库
- Codeforces 402A 402B 402C 402D
- java for循环的几种写法
- HDU 1.2.7 Identity Card
- 2013级C++第4周(春)项目——再和对象找感觉【项目4扩展1(选做)】
- ARM汇编协处理器指令
- apis.view 之 Animation,AutoComplete,Baseline,Chronometer
- 2014手游之变-热酷游戏首席执行官刘勇
- 加载TQ2440驱动-hello world 模块
- (libgdx学习)Continuous & non continuous rendering