Codeforces Round #294 (Div. 2)
来源:互联网 发布:组态软件开发源代码 编辑:程序博客网 时间:2024/05/16 19:48
一堆傻逼题
直接上代码
1
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;char p[10][10];int w, b;int main() { for (int i = 1; i <= 8; i++) scanf("%s", &p[i][1]); for (int i = 1; i <= 8; i++) for (int j = 1; j <= 8; j++) { switch(p[i][j]) { case 'Q':{w+=9;break;} case 'R':{w+=5;break;} case 'B':{w+=3;break;} case 'N':{w+=3;break;} case 'K':{break;} case 'P':{w+=1;break;} case 'q':{b+=9;break;} case 'r':{b+=5;break;} case 'b':{b+=3;break;} case 'n':{b+=3;break;} case 'k':{break;} case 'p':{b+=1;break;} } } if (w > b) printf("White\n"); else if (w<b) printf("Black\n"); else printf("Draw\n"); return 0;}
2
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <map>using namespace std;typedef long long LL;#define N 101111int n, x, p[N], q[N];map<int, int> P, Q;int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &x); Q[x]++; q[i] = x; } for (int i = 1; i < n; i++) { scanf("%d", &x); Q[x]--; P[x]++; p[i] = x; } for (int i = 1; i <= n; i++) if (Q[q[i]]) { printf("%d\n", q[i]); break; } for (int i = 2; i < n; i++) { scanf("%d", &x); P[x]--; } for (int i = 1; i < n; i++) if (P[p[i]]) { printf("%d\n", p[i]); break; } return 0;}
3
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;int n, m, res;int main() { scanf("%d%d", &n, &m); for (int i = 0; i <= n; i++) { int cnt = min(m/2, i); int ln = n - cnt; int lm = m - cnt * 2; res = max(res, cnt + min(lm, ln/2)); } printf("%d\n", res); return 0;}
4
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <map>using namespace std;typedef long long LL;#define N 101111map<LL, LL> sc[27];int val[99];LL res, V[N], v[N];char p[N];int main() { for (int i = 0; i < 26; i++) scanf("%d", val + i); scanf("%s", p + 1); int n = strlen(p + 1); for (int i = 1; i <= n; i++) p[i] -= 'a'; for (int i = 1; i <= n; i++) v[i] = val[p[i]]; for (int i = n - 1; i >= 0; i--) V[i] = V[i + 1] + v[i + 1]; for (int i = 1; i <= n; i++) { int x = p[i]; res += sc[x][V[i-1]]; sc[x][V[i]]++; } printf("%I64d\n", res); return 0;}
5
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;#define N 111111struct node { int to, last;}map[N<<1];int last[N], top;void link(int u, int v) { map[++top].to = v; map[top].last = last[u]; last[u] = top;}int Q[N];int n, dep[N], fa[N], son[N],st[N][22];bool vis[N];void Prepare() { int tail = 1, rear = 1; dep[1] = Q[1] = vis[1] = 1; while (tail <= rear){ int x = Q[tail++]; for (int i = last[x]; i; i = map[i].last) { int to = map[i].to; if (!vis[to]) { dep[to]=dep[x]+1; vis[to]=1; fa[to]=x; Q[++rear]=to; } } } for (int i = n; i >= 1; i--) { int x = Q[i]; for (int j = last[x]; j; j = map[j].last) { int to = map[j].to; if (dep[to] == dep[x]+1) son[x] += son[to]; } son[x]++; } for (int i = 1; i <= n; i++) { int x = Q[i]; st[x][0] = x; for (int j = 1; j <= 20; j++) st[x][j] = st[fa[st[x][j-1]]][j-1]; }}int Work(int step, int x) {// printf("Get %d %d\n",x,step); while (step>=4) { int cc = 1; for (int i = 0; i <= 20; i++) { if (cc > step) { cc /= 2; step -= cc; x = fa[st[x][i-1]]; break; } cc <<= 1; } } while (step--) x = fa[x]; return x;}void Solve(int u, int v) { if (dep[u] > dep[v]) swap(u, v); if (u == v) { printf("%d\n", n); return; } int cnt = 0, su = u, sv = v; while (dep[v] - dep[u] >= 5) { for (int i = 0; i <= 20; i++) if (dep[st[v][i]] < dep[u]) { int nv = st[v][i-1]; cnt += dep[v] - dep[nv]; v = nv; break; } } while (dep[v] > dep[u]) { cnt++; v = fa[v]; } while (st[u][3] != st[v][3]) { if (fa[u] == fa[v]) { cnt += 2; u = fa[u]; v = fa[v]; break; } for (int i = 2; i <= 20; i++) if (st[u][i] == st[v][i]) { int nu = st[u][i-1]; cnt += (dep[u] - dep[nu]) << 1; u = st[u][i-1]; v = st[v][i-1]; break; } } while (u != v) { u = fa[u]; v = fa[v]; cnt += 2; } if (cnt % 2) { printf("0\n"); return; } int lca = u; u = su; v = sv; int tp = Work(cnt/2, dep[u]>dep[v]?u:v); if (lca == tp) { printf("%d\n", n - son[Work(dep[u]-dep[lca]-1, u)] - son[Work(dep[v]-dep[lca]-1,v)]); return; } lca = dep[u] > dep[v] ? u : v; printf("%d\n",son[tp] - son[Work(dep[lca]-dep[tp]-1,lca)]);}int main() { int m, u, v; scanf("%d", &n); for (int i = 1; i < n; i++) { scanf("%d%d", &u, &v); link(u, v); link(v, u); } Prepare(); scanf("%d", &m); while (m--) { scanf("%d%d", &u, &v); Solve(u, v); } return 0;}
0 0
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2)
- Codeforces Round #294 (Div. 2) ABCDE
- Codeforces Round #294 (Div. 2) C
- Codeforces Round #294 (Div. 2) D
- Codeforces Round #294 (Div. 2) (ABCDE题解)
- Codeforces Round #294 (Div. 2) E
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- 3月的开始
- 五个免费UML建模工具
- 【Ogre引擎架构】 第一讲 从零开始 解析角色模型文件(一)
- 学习笔记:
- IOS开发中的内存管理(一)
- Codeforces Round #294 (Div. 2)
- IOS开发中的内存管理(二)
- delphi编程里bool跟boolean类型的区别
- UVALive - 4254 Processor 二分+优先队列
- javascript正则表达式修饰符之global(/g)的使用
- BZOJ 2055 80人环游世界 有上下界的费用流
- get file's name from a folder using Java
- cocos2d3.x在win7的环境配置和安装
- UVA - 11627 Slalom 二分