题目链接: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 ;
}

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 ;
}

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 ;
}

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

  1. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  2. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  5. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  6. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

  7. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  8. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  9. AtCoder Beginner Contest 151 题解报告

    总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...

随机推荐

  1. iOS离屏渲染

    为什么会使用离屏渲染 当使用圆角,阴影,遮罩的时候,图层属性的混合体被指定为在未预合成之前不能直接在屏幕中绘制,所以就需要屏幕外渲染被唤起. 屏幕外渲染并不意味着软件绘制,但是它意味着图层必须在被显示 ...

  2. windows配置apache tomcat 集群

      1,安装包 httpd-2.2.22-win32-x86-no_ssl.msi 两个tomcat6 2,配置apachehttpd---配置的过程中有错误可以查看logs文件夹下的log文件进行排 ...

  3. mongodb与mongodb可视化工具adminMongo结合使用

    一,MongoDB的安置及配置 1,从MongoDB官网下载安装 https://www.mongodb.com/download-center#community 根据的电脑选择合适的版本安装: 根 ...

  4. Python操作远程机器

    操作远程机器主要使用的有paramiko,WMI(Windows Management Instrumentation),SMBConnection. paramiko paramiko使用SSH2协 ...

  5. 初阶html学习总结(一)(转)

    一:颜色代码 如果你想使用某种颜色,取得它的颜色值即可.比如,您想改变某些文字的颜色,您可以使用下面的代码:<font color=#ffc060 size=2>改变#符号后的代码即可改变 ...

  6. linq to sql 不能更新的问题

    今天在项目中用linq更新一个表的时候,结果怎么都更新不了,最蛋疼的是什么异常也不报,发现db.table1.isReadOnly为True 知道问题所在,百度后得到解决办法: 原来是我的表没有增加主 ...

  7. 关于Java继承体系中this的表示关系

    Java的继承体系中,因为有重写的概念,所以说this在子父类之间的调用到底是谁的方法,或者成员属性,的问题是一个值得思考的问题; 先说结论:如果在测试类中调用的是子父类同名的成员属性,这个this. ...

  8. 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(一)

    1.ViewPager实现Tab 首先实现底部和底部布局 <?xml version="1.0" encoding="utf-8"?> <Li ...

  9. C 标签使用

    JSTL 核心标签库标签共有13个,功能上分为4类: 1.表达式控制标签:out.set.remove.catch 2.流程控制标签:if.choose.when.otherwise 3.循环标签:f ...

  10. Linux中的sed解析

    简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...