题目链接: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. samba Nginx

    1.samba 2.nfs 3.crond 4.nginx ifconfig yum install net-tools -y ifconfig #查看所有已激活的网卡信息 ifconfig eth0 ...

  2. 10-10C#基础---数据类型之间的转换

    10-10  C#基础数据类型转换(熟练掌握) 第一课 数据类型之间的转换 基本类型的转换:自动转换(隐式转换)和强制转换(显示转换) 装箱转换:允许值类型隐式转换成引用类型. 拆箱转换:允许将引用类 ...

  3. C#操作JSON专题

    第一章:C#如何拿到从http上返回JSON数据? 第二章:C#如何解析JSON数据?(反序列化对象) 第三章:C#如何生成JSON字符串?(序列化对象) 第四章:C#如何生成JSON字符串提交给接口 ...

  4. 有关less 处理@arguments的一些高级技巧

    //http://stackoverflow.com/questions/14350749/less-arguments-with-linear-gradients-commas .mixin(... ...

  5. 使用GSON来生成JSON数据

    第二种方法: 当不需要显示某个属性时,在不需要显示出的属性前加transient关键字即可满足 使用gson来解析 使用gson解析 带日期转换 集合类解析:gson中的数组与java中集合类都是对应 ...

  6. 通过测试确定GCC中 INT DOUBLE的最大/最小值和精度(DOUBLE)

    INT 确定最大/最小值 由于达到极限之后会变符号,直接循环判断条件即可 DOUBLE确定精度 设置一个DOUBLE变量初始值为1/3.0,每次*10,然后取整数部分,当两次的结果相同时说明已经到最大 ...

  7. c类库,委托,var ,运算符 is 和 as 。

    类库(Class Library)  格式   .dll  文件 类库   就是类的仓库 c#代码被编译过以后的文件,不可阅读,不可修改,只能调用. 类库是一个综合性的面向对象的可重用类型集合,这些类 ...

  8. 面试题:struts 值栈 有用

    一. 核心部分 1. [核心试题]完成当天课堂练习 2. [多选题] 阅读如下代码中,下列哪种方式可以在页面正确迭代获取集合中的数据 (ABC) public String add(){ ValueS ...

  9. ae中用粒子系统做的特效怎么循环

  10. Luogu 3586 [POI2015]LOG

    考虑离散化后开权值线段树. 设序列中不小于$s$的数有$cnt$个,小于$s$的数的和为$sum$. 那么操作Z能成功的充要条件是$sum \geq (c - cnt) * s$. 如果序列中不小于$ ...