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/ ...
随机推荐
- 第 十五 课 Go 语言范围(Range)
Go 语言中 range 关键字用于 for 循环中迭代数组(array).切片(slice).通道(channel)或集合(map)的元素 package main import "fmt ...
- CSS2实用知识点详解
CSS相关知识回顾目录 CSS2选择器 假选择器的使用 属性选择器的使用 边框设置 背景设置 字体设置 文本属性 a标签假选择器使用 列表设置 表格设置 鼠标设置 单位设置 隐藏显示 位置设置 清除浮 ...
- 空中楼阁 ( House )最短路
题目描述: 话说Z4阴差阳错地来到了神秘岛.不久,他们发现,这是一个由n个小岛和一个中心岛组成的群岛,群岛之间有m座桥.令他们感到惊讶的是,这些桥并不是固定不变的,经较长时间的观察,发现它们会随时间作 ...
- 基本的数据类型 void关键字 都存在类类型
- 通过测试确定GCC中 INT DOUBLE的最大/最小值和精度(DOUBLE)
INT 确定最大/最小值 由于达到极限之后会变符号,直接循环判断条件即可 DOUBLE确定精度 设置一个DOUBLE变量初始值为1/3.0,每次*10,然后取整数部分,当两次的结果相同时说明已经到最大 ...
- sql基本查询语句练习
student(S#,Sname,Sage,Ssex) 学生表 S#:学号: Sname:学生姓名:Sage:学生年龄:Ssex:学生性别 Course(C#,Cname,T#) 课程表 ...
- cocos2d-js 热更新模块 使用AssetsManager
原帖子地址:http://cn.cocos2d-x.org/tutorial/show?id=1186 在这个文章中原作者已经说的很清楚,我在这个其他改动一些适用我项目中需求 1.满足Web和Nati ...
- mac 彻底卸载Paragon NTFS
之前安装了paragon NTFS,试用期过了就卸载了,但是每天还是会提示“试用期已到期”,看着很烦. 百度了一下,发现网上的版本可能比较老了,和我的情况不太一样,但道理应该是一样的. 彻底删除方法: ...
- 项目一:第十一天 2、运单waybill快速录入 3、权限demo演示-了解 5、权限模块数据模型 6、基于shiro实现用户认证-登录(重点)
1. easyui DataGrid行编辑功能 2. 运单waybill快速录入 3. 权限demo演示-了解 4. Apache shiro安全框架概述 5. 权限模块数据模型 6. 基于shiro ...
- <%@ include file=""%>与<jsp:include page=""/>区别(转)
http://www.iteye.com/topic/312500/ 我们都知道在jsp中include有两种形式,分别是Include指令:<%@ include file="&qu ...