为啥最近都没有arc啊...

A - Favorite Sound

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n') #define I_int ll
inline I_int read() {
I_int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char F[200];
inline void write(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int }
using namespace io; using namespace std; #define N 100010 int a, b, c; int main() {
in(a), in(b), in(c);
printf("%d\n", min(b / a, c));
}

B - K-th Common Divisor

显然,就是求gcd的第k小的因子。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n') #define I_int ll
inline I_int read() {
I_int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char F[200];
inline void write(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int }
using namespace io; using namespace std; #define N 100010 int a, b, k, d[N], tot; int main() {
in(a), in(b), in(k);
int g = __gcd(a, b);
for(int i = 1; i * i <= g; ++i) {
if(g % i == 0) {
d[++tot] = i;
if(g / i != i) d[++tot] = g / i;
}
}
sort(d+1, d + tot + 1); reverse(d + 1, d + tot + 1);
printf("%d\n", d[k]);
}

C - Unification

栈的经典题。。。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n') #define I_int ll
inline I_int read() {
I_int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char F[200];
inline void write(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int }
using namespace io; using namespace std; #define N 100010
char s[N];
int n, st[N]; int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
int ans = 0, top = 0;
for(int i = 1; i <= n; ++i) s[i] -= '0';
for(int i = 1; i <= n; ++i) {
if(top && s[top] ^ s[i]) {++ans, --top; continue;}
s[++top] = s[i];
}
printf("%d\n", ans * 2);
}

D - Decayed Bridges

正着计数太麻烦了。

考虑最后一条边断掉之后答案肯定是\(n(n-1)/2\)。

用个经典的套路,把删边弄成倒着连边。

那么每次多连一条边,联通的点数就多了\(siz_x*siz_y\)

用\(n(n-1)/2\)减去\(siz_x*siz_y\)即可。

注意longlong。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n') #define I_int ll
inline I_int read() {
I_int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
char F[200];
inline void write(I_int x) {
if (x == 0) return (void) (putchar('0'));
I_int tmp = x > 0 ? x : -x;
if (x < 0) putchar('-');
int cnt = 0;
while (tmp > 0) {
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int }
using namespace io; using namespace std; #define N 100010 int n, m;
int a[N], b[N], f[N];
ll siz[N];
ll ans = 0, sum = 0, res[N];
int find(int x) {
if(f[x] == x) return x;
else return f[x] = find(f[x]);
}
int main() {
in(n), in(m);
sum = (ll)(n * (n - 1ll) / 2ll);
for(int i = 1; i <= m; ++i) in(a[i]), in(b[i]);
for(int i = 1; i <= n; ++i) f[i] = i, siz[i] = 1ll;
for(int i = m; i; --i) {
res[i] = sum - ans;
int x = find(a[i]), y = find(b[i]);
if(x != y) {
ans += (ll)siz[x] * siz[y];
siz[x] += siz[y];
f[y] = x;
}
}
for(int i = 1; i <= m; ++i) printf("%lld\n", res[i]);
}

AtCoder Beginner Contest 120 解题报告的更多相关文章

  1. AtCoder Beginner Contest 122 解题报告

    手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...

  2. AtCoder Beginner Contest 146解题报告

    题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...

  3. Atcoder Beginner Contest 124 解题报告

    心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...

  4. AtCoder Beginner Contest 118 解题报告

    A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...

  5. AtCoder Beginner Contest 117 解题报告

    果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...

  6. AtCoder Beginner Contest 132 解题报告

    前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...

  7. AtCoder Beginner Contest 129 解题报告

    传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...

  8. AtCoder Beginner Contest 127 解题报告

    传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...

  9. AtCoder Beginner Contest 126 解题报告

    突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...

随机推荐

  1. CNN那么多的网络有什么区别吗?如何对CNN网络进行修改?

    https://www.zhihu.com/question/53727257/answer/136261195 http://blog.csdn.net/csmqq/article/details/ ...

  2. canvas添加水印

    <canvas id="canvas"></canvas><canvas id="water"></canvas> ...

  3. 20165215 2017-2018-2 《Java程序设计》第6周学习总结

    20165215 2017-2018-2 <Java程序设计>第6周学习总结 教材学习内容总结 chapter8 Java把String类定义为final类,即String类不能有子类 用 ...

  4. 第三方统计分析埋点工具对比,神策、Ptmind、GrowingIO、国双,还有谷歌分析,谁更好?

    第三方统计分析埋点工具对比,神策.Ptmind.GrowingIO.国双,还有谷歌分析,谁更好?https://www.colabug.com/2985393.html GA.Mixpanel 和神策 ...

  5. go语言,golang学习笔记2 web框架选择

    go语言,golang学习笔记2 web框架选择 用什么go web框架比较好呢?能不能推荐个中文资料多的web框架呢? beego框架用的人最多,中文资料最多 首页 - beego: 简约 & ...

  6. vue 父子组件

    组件 什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊 ...

  7. HDU 2176 取(m堆)石子游戏 (尼姆博奕)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2176 m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎 ...

  8. ASP.NET Core Web API 索引 (更新Redis in .NET Core)

    https://www.cnblogs.com/cgzl/p/9178672.html

  9. 委托、匿名函数到lambda表达式

    在C#2.0之前就有委托了,在2.0之后又引入了匿名方法,C#3.0之后,又引入了Lambda表达式,他们三者之间的顺序是:委托->匿名表达式->Lambda表达式,微软的一步步升级,带给 ...

  10. Linux下解析域名命令-dig 命令使用详解

    Linux下解析域名除了使用nslookup之外,开可以使用dig命令来解析域名,dig命令可以得到更多的域名信息.dig 命令主要用来从 DNS 域名服务器查询主机地址信息.dig的全称是 (dom ...