# | Who | = | Penalty | * | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|
479 | arkethos | 4 | 247 |
+ 00:08 |
+ 00:19 |
+1 00:59 |
+2 01:41 |
|||
479 | ![]() |
4 | 247 |
+ 00:04 |
-1 |
+1 00:27 |
+2 01:47 |
+ 00:49 |
||
481 | MeePwn# | 4 | 248 |
+ 00:14 |
+ 00:21 |
+ 00:54 |
+3 01:39 |
|||
482 | ![]() |
4 | 251 |
+ 00:06 |
+ 00:10 |
+ 00:17 |
+5 01:58 |
|||
483 | iskander232 | 4 | 252 |
+1 00:06 |
+2 00:23 |
+ 00:17 |
-3 |
+2 01:46 |
Chess For Three
默认第一场比赛由AB进行

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> using std::vector; using std::queue; using std::map; using std::sort; using std::string; using std::lower_bound; using std::upper_bound; #define read(x) scanf("%d", &x) #define reads(x) scanf("%s", x) #define write(x) printf("%d ", x) #define writes(x) printf("%s ", x) #define writeln(x) printf("%d ", x) #define writesln(x) printf("%s ", x) #define fillchar(x, a) memset(x, a, sizeof(x)) typedef long long llint; /*data structure*/ /*data structure*/ int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } /*global variable*/ int a[200]; /*global variable*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; read(n); for (int i = 0; i < n; i++) { read(a[i]); a[i]--; } int p1 = 0, p2 = 1, spec = 2; bool flag1 = true; for (int i = 0; i < n; i++) { if (a[i] == spec) { flag1 = false; break; } if (p1 == a[i]) { int t = p2; p2 = spec; spec = t; } else { int t = p1; p1 = spec; spec = t; } } if (flag1) printf("YES "); else printf("NO "); return 0; }
Beautiful Divisors
直接把符合条件的数列出来找

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> using std::vector; using std::queue; using std::map; using std::sort; using std::string; using std::lower_bound; using std::upper_bound; #define read(x) scanf("%d", &x) #define reads(x) scanf("%s", x) #define write(x) printf("%d ", x) #define writes(x) printf("%s ", x) #define writeln(x) printf("%d ", x) #define writesln(x) printf("%s ", x) #define fillchar(x, a) memset(x, a, sizeof(x)) typedef long long llint; /*data structure*/ /*data structure*/ int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } /*global variable*/ int a[100]; /*global variable*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; for (int i = 1;; i++) { a[i] = ((1 << i) - 1) * (1 << (i - 1)); if (a[i] > 100000) { n = i; break; } } int x; read(x); for (int i = n; i >= 1; i--) { if (x % a[i] == 0) { writeln(a[i]); break; } } return 0; }
Rumor
贪心,每次贿赂还不知道的人里边底线最低的

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> #include<functional> using std::priority_queue; using std::vector; using std::queue; using std::map; using std::sort; using std::string; using std::lower_bound; using std::upper_bound; #define read(x) scanf("%d", &x) #define reads(x) scanf("%s", x) #define write(x) printf("%d ", x) #define writes(x) printf("%s ", x) #define writeln(x) printf("%d ", x) #define writesln(x) printf("%s ", x) #define fillchar(x, a) memset(x, a, sizeof(x)) typedef long long llint; /*data structure*/ struct cha { int id; llint c; friend bool operator< (cha n1, cha n2) { return n1.c > n2.c; } }; /*data structure*/ int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } /*global variable*/ priority_queue<cha> q; vector<int> G[100005]; bool v[100005]; /*global variable*/ void dfs(int x) { for (int i = 0; i < G[x].size(); i++) { int u = G[x][i]; if (v[u]) continue; v[u] = true; dfs(u); } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n, m; read(n); read(m); while (!q.empty()) q.pop(); for (int i = 1; i <= n; i++) { cha ccc; ccc.id = i; scanf("%lld", &ccc.c); q.push(ccc); G[i].clear(); } for (int i = 0; i < m; i++) { int x, y; read(x); read(y); G[x].push_back(y); G[y].push_back(x); } fillchar(v, false); long long ans = 0; while (!q.empty()) { cha x = q.top(); q.pop(); if (v[x.id]) continue; ans += x.c; v[x.id] = true; dfs(x.id); } printf("%I64d ", ans); return 0; }
Credit Card
首先,早上不存钱,把所有操作模拟一遍,记录每天晚上结束时的钱数m,如果某一天超过d,输出-1。
因为钱不会凭空消失,所以在某一天存入钱后,当天及以后每天的m值增加相同大小。
为了尽量少去,显然只有当a为0的日子才去,存的钱应该在不会导致之后超出d的情况下尽量多,为d减去之后的m值中最大的,再减去之前已经存过的钱数。

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> #include<functional> using std::priority_queue; using std::vector; using std::queue; using std::map; using std::sort; using std::string; using std::lower_bound; using std::upper_bound; #define read(x) scanf("%d", &x) #define reads(x) scanf("%s", x) #define write(x) printf("%d ", x) #define writes(x) printf("%s ", x) #define writeln(x) printf("%d ", x) #define writesln(x) printf("%s ", x) #define fillchar(x, a) memset(x, a, sizeof(x)) typedef long long llint; /*data structure*/ /*data structure*/ int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } /*global variable*/ int a[100005]; llint m[100005], max[100005]; /*global variable*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; llint d; scanf("%d%I64d", &n, &d); for (int i = 0; i < n; i++) read(a[i]); m[0] = a[0]; for (int i = 1; i < n; i++) { m[i] = m[i - 1] + a[i]; } for (int i = 0; i < n; i++) { if (m[i] > d) { printf("-1 "); return 0; } } max[n - 1] = m[n - 1]; for (int i = n - 2; i >= 0; i--) { if (m[i] > max[i + 1]) max[i] = m[i]; else max[i] = max[i + 1]; } int ans = 0; llint add = 0, l, r; bool flag = true; for (int i = 0; i < n; i++) { if (a[i] != 0) continue; if (m[i] + add >= 0) continue; l = (llint) - 1 * m[i] - add; r = d - (max[i] + add); if (l > r) { flag = false; break; } ans++; add += r; } if (flag) printf("%d ", ans); else printf("-1 "); return 0; }
Counting Arrays
把x分解质因数,对于有cnt个的质因子,答案乘以C(y+cnt-1,cnt),关于这类问题,有一张总结的图(懒得编辑了,治疗一下颈椎病吧):
这题被这个数据搞了一下:
1
524288 1000000
这个524288=1<<19,y是最大值1000000,加起来就是1000018,而我数组开的是1000005,于是就跪了。脸打的啪啪啪,牛批啊老哥。

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> #include<functional> #include<iostream> //#include<bits/stdc++.h> using namespace std; #define fillchar(x, a) memset(x, a, sizeof(x)) typedef long long lint; /*data structure*/ template <int size> class NoCombination { public: lint fac[size], inv[size], f[size]; lint mod; void init(lint m) { mod = m; fac[0] = fac[1] = inv[0] = inv[1] = f[0] = f[1] = 1; for (int i = 2; i < size; i++) { fac[i] = fac[i - 1] * i % mod; f[i] = (mod - mod / i) * f[mod % i] % mod; inv[i] = inv[i - 1] * f[i] % mod; } } lint C(lint a, lint b) { return fac[a] * inv[b] % mod * inv[a - b] % mod; } }; /*data structure*/ int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } /*global variable*/ NoCombination<1100005> nc; const lint mod = 1000000007; bool f[1100005]; int p[1100005], m = 0; /*global variable*/ /*function*/ inline lint pow(lint a, lint b, lint p) { lint rtn = 1; while (b) { if (b & 1) rtn = rtn * a % p; a = a * a % p; b >>= 1; } return rtn; } /*function*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif std::ios::sync_with_stdio(0), cin.tie(0); nc.init(mod); fillchar(f, true); f[0] = f[1] = false; for (int i = 2; i < 1000000; i++) { if (f[i]) { p[m++] = i; for (int j = i + i; j < 1000000; j+=i) f[j] = false; } } int q, x, y; lint ans; cin >> q; while (q--) { cin >> x >> y; ans = 1; int maxp = (int)sqrt(x); for (int i = 0; i < m; i++) { if (x == 1 || p[i] > maxp) break; if (x % p[i] != 0) continue; int cnt = 0; while (x % p[i] == 0) x /= p[i], cnt++; ans = ans * nc.C(y + cnt - 1, cnt) % mod; } if (x > 1) ans = ans * y % mod; ans = ans * pow(2, y - 1, mod) % mod; cout << ans << endl; } return 0; } //33353503
Subtree Minimum Query
这道题跟以前做过的一道题解法差不多,记录从每个点往下走1步,2步,4步,8步......能得到的最小的a,然后对于查询的k步用二进制表示出来各个位一凑就行。比如走7步相当于从第0个点走到第4个点的最小值、从第4个点走到第6个点的最小值、第6个点走到第7个点的最小值这3个最小值中的最小值,这样复杂度就变成了对数级别的。有几个可能会出错的坑,卡了我很久才弄明白,整理成两组测试数据:
2 1 1 2 1 2 1 1 100 |
4 1 10000 10000 10000 1 1 2 2 3 1 4 1 1 2 |

#pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<string> #include<functional> //#include<bits/stdc++.h> using namespace std; typedef long long lint; vector<int> G[100005]; vector<int> P[100005][25]; int Q[100005][25]; int a[100005], fa[100005], dep[100005]; vector<int> vi[2]; int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } void dfs(int x) { for(int i = 0; i < G[x].size(); i++) { int u = G[x][i]; if(u == fa[x]) continue; fa[u] = x; dfs(u); if(dep[u] + 1 > dep[x]) dep[x] = dep[u] + 1; } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif std::ios::sync_with_stdio(0), cin.tie(0); int n, r, x, y; cin >> n >> r; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) { cin >> x >> y; G[x].push_back(y); G[y].push_back(x); } memset(fa, 0, sizeof(fa)); memset(dep, 0, sizeof(dep)); fa[r] = -1; dfs(r); for(int i = 1; i <= n; i++) { Q[i][0] = a[i]; for(int j = 0; j < G[i].size(); j++) { int u = G[i][j]; if(u == fa[i]) continue; P[i][0].push_back(u); Q[i][0] = min(Q[i][0], a[u]); } } for(int j = 1; j < 25; j++) { for(int i = 1; i <= n; i++) { Q[i][j] = Q[i][j - 1]; for(int k = 0; k < P[i][j - 1].size(); k++) { int u = P[i][j - 1][k]; Q[i][j] = min(Q[i][j], Q[u][j - 1]); for(int p = 0; p < P[u][j - 1].size(); p++) { int v = P[u][j - 1][p]; P[i][j].push_back(v); } } } } int t, p, q, cur, step, ans, last = 0; cin >> t; while(t--) { cin >> p >> q; //p = (p + last) % n + 1, q = (q + last) % n; if(q > dep[p]) q = dep[p]; int pp = p, qq = q; vi[0].clear(), vi[1].clear(); ans = a[p]; cur = 0; vi[cur].push_back(p); step = 0; while(q) { vi[1 - cur].clear(); if(q & 1) { for(int i = 0; i < vi[cur].size(); i++) { int u = vi[cur][i]; ans = min(ans, Q[u][step]); for(int j = 0; j < P[u][step].size(); j++) { vi[1 - cur].push_back(P[u][step][j]); } } cur = 1 - cur; } step++; q >>= 1; } cout << ans << endl; last = ans; } return 0; }