AtCoder Beginner Contest 120 题解
题目链接:https://atcoder.jp/contests/abc120
A Favorite Sound
分析:答案为
。
代码:
#include <iostream> using namespace std; int main()
{
int a, b, c;
cin>>a>>b>>c;
cout<<min(b / a, c)<<endl;
return ;
}
B K-th Common Divisor
分析:A、B范围很小,枚举即可。注意要判断A、B的大小,从大到小枚举。
代码:
#include <cstdio>
#include <iostream> using namespace std; int main()
{
int a, b, k;
scanf("%d %d %d", &a, &b, &k);
int imax = max(a, b);
int cnt = ;
for(int i = imax; i >= ; --i)
{
if(a % i == && b % i == )
cnt++;
if(cnt == k)
{
printf("%d\n", i);
break;
}
}
return ;
}
C Unification
分析:因为S串里只有‘0’和‘1’,所以无论如何只要还有‘0’和‘1’同时存在,就一定可以继续该操作。答案就是‘0’和‘1’的数量取最小值的两倍(一次操作两个cube)。
代码:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
char s[];
scanf("%s", s);
int slen = strlen(s);
int zero = , one = ;
for(int i = ; i < slen; ++i)
{
if(s[i] == '')
zero++;
else if(s[i] == '')
one++;
}
printf("%d\n", min(zero, one)*);
return ;
}
D Decayed Bridges
分析:建边后删边判断连通比较麻烦。我们可以考虑倒着建边。当所有边都删完后,
。然后倒序加入每一条边,inconvenience减去加入一条边后连通的点对。判断是否在同一个连通集里可以用并查集维护。这里需要开一个数组s记录每一个集合内的点个数,初始所有点为1.之后更新的时候只要更新并查集里的根节点个数即可。每加一条边
。
代码:
#include <iostream>
#include <cstdio> using namespace std; typedef long long ll; struct bridge
{
int a;
int b;
}dict[]; int parent[], trank[];
ll sum;
ll ans[] = {};
ll s[]; void init()
{
for(int i = ; i < ; ++i)
{
parent[i] = -;
trank[i] = ;
}
} int find_root(int x)
{
int x_root = x;
while(parent[x_root] != -)
x_root = parent[x_root];
return x_root;
} int union_set(int x, int y)
{
int x_root = find_root(x);
int y_root = find_root(y);
if(x_root == y_root)
return ;
else
{
if(trank[x_root] > trank[y_root])
{
parent[y_root] = x_root;
sum -= s[x_root]*s[y_root];
s[x_root] += s[y_root];
}
else if(trank[y_root] > trank[x_root])
{
parent[x_root] = y_root;
sum -= s[x_root]*s[y_root];
s[y_root] += s[x_root];
}
else
{
parent[y_root] = x_root;
trank[x_root]++;
sum -= s[x_root]*s[y_root];
s[x_root] += s[y_root];
}
}
return ;
} int main()
{
init();
int n, m;
scanf("%d %d", &n, &m);
for(int i = ; i < m; ++i)
scanf("%d %d", &dict[i].a, &dict[i].b);
for(int i = ; i <= n; ++i)
s[i] = ;
sum = 1ll*n*(n-)/;
for(int i = m - ; i >= ; --i)
{
ans[i] = sum;
int x = dict[i].a;
int y = dict[i].b;
union_set(x, y);
}
for(int i = ; i < m; ++i)
cout<<ans[i]<<endl;
return ;
}
AtCoder Beginner Contest 120 题解的更多相关文章
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 151 题解报告
总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...
随机推荐
- Cassandra 学习三 安装
1: 下载Cassandra 2 解压 3 设置环境变量 4 修改cassandra里的conf目录下配置文件 配置文件地址是 D:\cassandra\apache ...
- C# Lambda快速深度拷贝
背景:今天上班在班车上和一个同事讨论有关C#拷贝效率的问题,聊到了多种深度拷贝方法,其中就提到了一种Lambda表达式拷贝的方法,这位同事说这种深度拷贝快是快但是如果对象里面再嵌入对象就不能深度拷贝了 ...
- Windows Backdoor Tips
名称:在用户登录时,运行这些程序 位置: Computer Configuration\\Policies\\Administrative Templates\\System\\Logon\\ 中 d ...
- 语法错误: 标识符“acosf”
1>e:\vs2010\vc\include\cmath(19): error C2061: 语法错误: 标识符“acosf” 1>e:\vs2010\vc\include\cmath(1 ...
- C++ 学习之---C++基础理论知识(也适合面试回顾)
C++ 语言编写的基础练习 具体案例放在github中 github地址:https://github.com/Master-fd/C-Base 1. 操作符重载 2. 构造与析构 3. 函数模板 4 ...
- Git实用技巧
1.关于版本控制系统 (1)本地版本控制系统 (2)集中化的版本控制系统 (3)分布式版本控制系统 2.Git的三种状态 对于任何一个文件,在 Git 内都只有三种状态: 已提交(committed) ...
- 理解和正确使用Java中的断言(assert)
一.语法形式: Java2在1.4中新增了一个关键字:assert.在程序开发过程中使用它创建一个断言(assertion),它的语法形式有如下所示的两种形式:1.assert conditio ...
- 【277】◀▶ Python 列表/元组/字典说明
目录: 前言 一.访问列表中的值 二.更新列表 三.删除列表元素 四.Python 列表脚本操作符 五.Python 列表函数 & 方法 参考:Python 列表(List)使用说明 列表截取 ...
- [Python Study Notes]行人检测
# -------------------------------------------------------------- # @文件: 行人识别.py # @工程: blog # @时间: 2 ...
- 为SSRS配置SMTP服务器身份验证
此处设置外邮地址却无法填写邮箱密码 一.安装SMTP服务 1.在服务管理器中单击“功能” 2.单击“添加功能”打开“添加功能向导”对话框 3.在“选择功能”页上选择“SMTP服务器”并选择“添加必须的 ...