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的更多相关文章

  1. AtCoder Beginner Contest 187 F - Close Group

    题目链接 点我跳转 题目大意 给你一张完全图,你可以删除任意数量的边 要求删除完后剩余的所有子图必须是完全图 问完全子图数量最少是多少 解题思路 定义 \(ok[i]\) 表示状态为 \(i\) 时所 ...

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  4. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  5. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  6. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  7. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  8. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  9. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

随机推荐

  1. 分块 && 例题 I Hate It HDU - 1754

    分块算法: 分块就是对暴力方法的一种优化:                          _ 假设我们总共的序列长度为n,然后我们把它切成√n 块,然后把每一块里的东西当成一个整体来看,完整块:被 ...

  2. C# List.Sort与IComparer接口及Comparison委托应用于集合排序

    C#里List.Sort的用法 using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  3. 国产网络损伤仪SandStorm -- 基本概念:什么是仿真引擎

    "仿真引擎"在网络损伤仪SandStorm(www.minismb.com)或者网络IP仿真损伤仪中是一个最基本概念,它就相当于一个由两个物理以太网口组成的"网桥&quo ...

  4. Linux系统启动过程内核文件丢失解决方法

    一.问题描述 公司近期因机房断电,导致服务器重启后,引导进入不了操作系统.经过检查发现启动文件缺失,导致系统启动失败,网上搜了好多资料,解决都比较零散,现结合实际处理经验和网友的建议整理接方案. 二. ...

  5. cccc超级酱油心得

    第一次线下比赛献给了cccc. 大致写写自己心得,比赛前一天晚上日常和室友在宿舍玩到11点多,洗漱上床.睡前突然想起第二天还有比赛,顿时激动加紧张.在床上刷了刷知乎和百度,看几道去年的真题,熬到了12 ...

  6. Makefile 赋值 函数定义 等小知识点

    1.赋值 == 到用的时候实际才去赋值:= 立刻赋值?= 未赋值才赋值+= 2.多层变量 多层变量引用(各种复杂组合...)a =bb= cc= dd =1$($($($(a)))) 最终等于1 3. ...

  7. Keras模型拼装

    在训练较大网络时, 往往想加载预训练的模型, 但若想在网络结构上做些添补, 可能出现问题一二... 一下是添补的几种情形, 此处以单输出回归任务为例: # 添在末尾: base_model = Inc ...

  8. Graphviz - Graph Visualization Software 开源可视化绘图工具(visio 类)

    http://www.graphviz.org/Download_windows.php Welcome to Graphviz Available translations:  Romanian,  ...

  9. yarn create & npx & npm init

    yarn create & npx & npm init https://www.npmtrends.com/npm-vs-npx-vs-yarn demo https://www.n ...

  10. js 获取包含emoji的字符串的长度

    let emoji_exp = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ ...