AtCoder Beginner Contest 187
A Large Digits
int n;
int main()
{
IOS;
int a, b, resa = 0, resb = 0;
cin >> a >> b;
while(a) resa += a % 10, a /= 10;
while(b) resb += b % 10, b /= 10;
cout << max(resa, resb) << endl;
return 0;
}
B Gentle Pairs
int n;
int x[N], y[N];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++ i) scanf("%d%d", &x[i], &y[i]);
int res = 0;
for(int i = 1; i <= n; ++ i)
for(int j = i + 1; j <= n; ++ j)
{
if(x[i] - x[j] == 0) continue;
if(x[i] - x[j] > 0)
{
if(y[i] - y[j] >= x[j] - x[i] && y[i] - y[j] <= x[i] - x[j])
res ++;
}
if(x[i] - x[j] < 0)
{
if(y[i] - y[j] <= x[j] - x[i] && y[i] - y[j] >= x[i] - x[j])
res ++;
}
}
printf("%d\n", res);
}
C 1-SAT
int n;
map mp;
string str;
int main()
{
IOS;
cin >> n;
for(int i = 1; i <= n; ++ i)
{
cin >> str;
if(str[0] == '!' && mp.count(str.substr(1)))
{
cout << str.substr(1) << endl;
return 0;
}
if(str[0] != '!' && mp.count("!" + str))
{
cout << str << endl;
return 0;
}
mp[str] = 1;
}
puts("satisfiable");
return 0;
}
D Choose Me
不选时\(A += a_i\), \(B += 0\), 选时 \(A += 0\), \(B += a_i + b_i\)
先考虑都不选,每选择一个相当于从\(A\)中减去一个\(a_i\),\(B\)加一个\(a_i + b_i\),因为是比较大小关系,所以等价于\(A\)不动,\(B + 2 \times a_i + b_i\)
int n;
struct zt
{
int a, b;
LL c;
}t[N];
bool cmp(zt a, zt b)
{
return a.c > b.c;
}
int main()
{
scanf("%d", &n);
LL sum = 0, res = 0;
for(int i = 1; i <= n; ++ i)
{
scanf("%d%d", &t[i].a, &t[i].b);
t[i].c = t[i].a * 2 + t[i].b;
sum += t[i].a;
}
sort(t + 1, t + n + 1, cmp);
for(int i = 1; i <= n; ++ i)
{
res += t[i].c;
if(res > sum) { printf("%d\n", i); break;}
}
return 0;
}
E Through Path
树上差分
以1号点为根,预处理每个点的深度.
若对于深度大的点所在分支(即它的子树)全部\(+x\),只需要对该点\(+x\).
若对于深度小的点所在分支全部\(+x\),可以看成所有点\(+x\),深度大的点所在子树\(-x\),故维护一个所有点的增加值,并对深度大的点\(-x\).
最后遍历一遍子树把标记下传即可.
int n, m;
struct Edge
{
int to, nxt;
}line[N * 2];
int fist[N], idx;
int dep[N];
LL d[N], res;
void add(int x, int y)
{
line[++ idx] = (Edge){y, fist[x]};
fist[x] = idx;
}
void dfs(int u, int far)
{
for(int i = fist[u]; i != -1; i = line[i].nxt)
{
int v = line[i].to;
if(v == far) continue;
dep[v] = dep[u] + 1;
dfs(v, u);
}
}
void dfs2(int u, int far)
{
for(int i = fist[u]; i != -1; i = line[i].nxt)
{
int v = line[i].to;
if(v == far) continue;
d[v] += d[u];
dfs2(v, u);
}
}
int main()
{
memset(fist, -1, sizeof fist);
scanf("%d", &n);
for(int i = 1; i < n; ++ i)
{
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
add(b, a);
}
dfs(1, -1);
scanf("%d", &m);
for(int i = 1; i <= m; ++ i)
{
int t, e, x;
scanf("%d%d%d", &t, &e, &x);
int a = line[2 * e].to, b = line[2 * e - 1].to;
if(dep[a] < dep[b] && t == 2) d[b] += x;
if(dep[a] > dep[b] && t == 1) d[a] += x;
if(dep[a] < dep[b] && t == 1) { d[b] -= x; res += x; }
if(dep[a] > dep[b] && t == 2) { d[a] -= x; res += x; }
}
dfs2(1, -1);
for(int i = 1; i <= n; ++ i) printf("%lld\n", d[i] + res);
return 0;
}
F Close Group
令f[i]表示状态i划分的团的个数集合中的最小值.
枚举i的子集s, f[i] = min(f[i], f[i - s] + f[s])
int n, m;
int conn[1 << N];
int f[1 << N];
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++ i)
{
int a, b;
scanf("%d%d", &a, &b);
a -- , b -- ;
conn[a] |= (1 << b);
conn[b] |= (1 << a);
}
for(int i = 0; i < n; ++ i) conn[i] |= (1 << i);
memset(f, 0x3f, sizeof f);
f[0] = 0;
for(int i = 1; i < (1 << n); ++ i)
{
int flag = 1;
for(int j = 0; j < n; ++ j)
if(i & (1 << j) && (conn[j] & i) != i)
{
flag = 0;
break;
}
if(flag) f[i] = 1;
for(int s = i; s; s = (s - 1) & i)
f[i] = min(f[i], f[i - s] + f[s]);
}
printf("%d\n", f[(1 << n) - 1]);
return 0;
}
2021.1.21
AtCoder Beginner Contest 187的更多相关文章
- AtCoder Beginner Contest 187 F - Close Group
题目链接 点我跳转 题目大意 给你一张完全图,你可以删除任意数量的边 要求删除完后剩余的所有子图必须是完全图 问完全子图数量最少是多少 解题思路 定义 \(ok[i]\) 表示状态为 \(i\) 时所 ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
随机推荐
- leetcode 1 两数之和 hashmap
主要是hashmap.还有边插入边查找,提高效率和降低空间复杂度. 之前一直用map,结果发现还有hashmap,效率更高. 注意名称空间为 using namespace __gnu_cxx; 问题 ...
- Gym 101170F Free Weights(二分)题解
题意:给出两行,每一行都有n个数组,一共有2 * n个,大小为1~n,每个有两个.现在可以进行操作:拿出一个物品i,然后放到一个空格,花费i.可以任意平移物品,平移没有花费.每一行空间无限.要求你把一 ...
- linux下新建用户
新建用户的两种方式: 一步步创建 useradd -m user1 #-m 是建立家目录 passwd user1 #设置密码 usermod -a -G root user1 #加入管理员 chsh ...
- 云原生系列1 pod基础
POD解决了什么问题? 成组资源调度问题的解决. mesos采用的资源囤积策略容易出现死锁和调度效率低下问题:google采用的乐观调度技术难度非常大: 而k8s使用pod优雅的解决了这个问题. po ...
- favicon.ico All In One
favicon.ico All In One link rel="icon" type="image/x-icon" href="http://exa ...
- JavaScript 实现 (ECMAScript 6)
JavaScript 的核心 ECMAScript 描述了该语言的语法和基本对象: DOM 描述了处理网页内容的方法和接口: BOM 描述了与浏览器进行交互的方法和接口. ECMAScript.DOM ...
- bash copy multi files
bash copy multi files # copy one file $ cp file1.js /var/www/html # copy multi files ??? no space $ ...
- URL parser All In One
URL parser All In One const url = new URL(`https://admin:1234567890@cdn.xgqfrms.xyz:8080/logo/icon.p ...
- Dart DevTools & Flutter
Dart DevTools & Flutter https://flutter.dev/docs/development/tools/devtools/overview https://dar ...
- CSS rulesets
CSS rulesets https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#CSS_rulesets https://css-tricks ...