AC日记——[SCOI2010]游戏 bzoj 1854
1854: [Scoi2010]游戏
Time Limit: 5 Sec Memory Limit: 162 MB
Submit: 4938 Solved: 1948
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2
3 2
4 5
Sample Output
HINT
【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
Source
思路:
这题的并查集做法简直逆天;
通过并查集把可能重复的属性都给链接到一块;
然后就开始进行合并判断哪些属性能用到;
然后从1开始到10000遍历;
哪个属性是false(没被合并)最大就是到那;
来,上代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 100005 using namespace std; int n,f[maxn]; bool if_[maxn]; char Cget; inline void in(int &now)
{
now=,Cget=getchar();
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
return ;
} int find(int x)
{
if(x==f[x]) return x;
f[x]=find(f[x]);
return f[x];
} int main()
{
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
in(n);int x,y;
for(int i=;i<=;i++) f[i]=i;
for(int i=;i<=n;i++)
{
in(x),in(y);
x=find(x),y=find(y);
if(x==y) if_[x]=true;
else
{
if(x>y) swap(x,y);
f[x]=y;
if_[x]=true;
}
}
for(int i=;i<=;i++)
{
if(!if_[i])
{
printf("%d\n",i-);
break;
}
}
return ;
fclose(stdin);
fclose(stdout);
}
AC日记——[SCOI2010]游戏 bzoj 1854的更多相关文章
- AC日记——[SCOI2009]游戏 bzoj 1025
[SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...
- AC日记——[SCOI2010]幸运数字 bzoj 1853
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2405 Solved: 887[Submit][Status] ...
- AC日记——[Scoi2010]序列操作 bzoj 1858
1858 思路: 恶心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 struct Tree ...
- 游戏(bzoj 1854)
Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性 ...
- AC日记——国王游戏 洛谷 P1080
国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...
- AC日记——色板游戏 洛谷 P1558
色板游戏 思路: sb题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 struct Tre ...
- AC日记——图灵机游戏 codevs 2292
2292 图灵机游戏 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description [Shadow 1]第二题 ...
- AC日记——[Hnoi2017]影魔 bzoj 4826
4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...
- AC日记——[LNOI2014]LCA bzoj 3626
3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...
随机推荐
- centos7无法切换startx
centos光盘安装后,显示命令行模式,通过startx无法进入图形界面? 解决方法:1.使用yum grouplist查看,根据显示的结果采用不同的界面格式,我用的是 yum groupinstal ...
- 拓展jQuery的serialize(),将form表单转化为json对象
jQuery 的 serialize() 方法经常会报 Uncaught TypeError: JSON.serializeObject is not a function 的错误, 原装的方法真的一 ...
- 《linux设备驱动开发详解》笔记——7并发控制
linux中并发无处不在,底层驱动需要考虑. 7.1 并发与竞争 7.1.1 概念 并发:Concurrency,多个执行单元同时.并行执行 竞争:Race Condistions,并发的执行单元对共 ...
- Tomcat上传文件报错:returned a response status of 403 Forbidden
出现这样的错误是没有权限对服务器进行写操作.需要在这个项目所在的tomcat中配置可写操作即可: 在tomcat的web.xml添加下面代码: <init-param><param- ...
- LeetCode(289)Game of Life
题目 According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cel ...
- 水题:UVa133-The Dole Queue
The Dole Queue Time limit 3000 ms Description In a serious attempt to downsize (reduce) the dole que ...
- 动态规划:Codeforces Round #427 (Div. 2) C Star sky
C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...
- 牛客练习赛29 B
炎热的早上,gal男神们被迫再操场上列队,gal男神们本来想排列成x∗x的正方形,可是因为操场太小了(也可能是gal男神太大了),校长安排gal男神们站成多个4∗4的正方形(gal男神们可以正好分成n ...
- UVa 1407 树形背包 Caves
这道题可以和POJ 2486 树形背包DP Apple Tree比较着来做. 参考题解 #include <iostream> #include <cstdio> #inclu ...
- EXCEL常用命令
查找和选择:定位条件(定位空值.错误值) 选择性粘贴