AtCoder Beginner Contest 120 解题报告
为啥最近都没有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 解题报告的更多相关文章
- AtCoder Beginner Contest 122 解题报告
手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...
- AtCoder Beginner Contest 146解题报告
题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...
- Atcoder Beginner Contest 124 解题报告
心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...
- AtCoder Beginner Contest 118 解题报告
A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...
- AtCoder Beginner Contest 117 解题报告
果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 129 解题报告
传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...
- AtCoder Beginner Contest 127 解题报告
传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...
- AtCoder Beginner Contest 126 解题报告
突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...
随机推荐
- BestCoder Round #55 ($)
C 构造一个矩阵,然后采用矩阵快速幂 #include <iostream> #include <algorithm> #include <string.h> #i ...
- 排序(I)
NSSortDescriptor 排序 Person类 #import <Foundation/Foundation.h> @interface Person : NSObject @pr ...
- IoC, DI,Spring.net
IoC : Inversion of Control , 控制反转,就是创建对象(实例)的权利由开发人员自己控制New转到了由容器来控制.实现了解耦. DI: Dependency Injection ...
- js里用append()和appendChild有什么区别?
parentNode.append()是还在试用期的方法,有兼容问题.是在parendNode节点中最后一个子节点后插入新Node或者DOMString(字符串,插入后为Text节点). 与paren ...
- javascript常用积累
一.JS动画与动作不一致解决: if(!$( "#handle").is(":animated")){ //判断元素是否处于动画状态 } 二.停止事件冒泡 ev ...
- MySQL性能测试工具sysbench的安装和使用
sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和PostgreSQL.当前 ...
- 自学Java第三个星期的总结
在这一周里我在网上学习了java的分支结构.Number&Matht类.Character类.string类.String Buffer和String Builder类以及数组和日期时间等有关 ...
- TensorFlow 分布式实践
此wiki主要介绍分布式环境使用的一些条件,一直所要注意的内容: 确保在此之前阅读过TensorFlow for distributed 1.集群描述 当前tensorflow 的版本(0.8.0), ...
- Django框架----logging配置
我写Django项目常用的logging配置.(追加在setting.py文件中) LOGGING = { 'version': 1, 'disable_existing_loggers': Fals ...
- Centos搭建Seafile个人网盘
1.安装依赖环境 yum install python python-setuptools python-imaging python-ldap python-memcached MySQL-pyth ...