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 ...
随机推荐
- Spring boot接受json赋值给java对象
Spring boot接受json赋值给java对象 新建 模板 小书匠 前言 写这个东西,一方面是我自己在做项目的时候,对json的使用还不是十分的熟悉,对spring boot的使用也不是很熟悉, ...
- 18/07/2017 R matrix
矩阵:二维数组,元素拥有相同模式(数值型,字符型或者逻辑型) mymatrix <- matrix (vector, nrow_num_of_rows, ncol_num_of_columns, ...
- percpu之静态变量
参考:Linux内核同步机制之(二):Per-CPU变量 CPU私有变量(per-CPU变量) 动态PCPU变量 setup_per_cpu_areas()初始化per-cpu数据. static v ...
- poj--1064
题意:有N条绳子,它们的长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子最长能有多长?答案保留到小数点后2位. 思路:这些最大最小化问题大多数可以用二分查找的方法来解题 用 d 表 ...
- BZOJ 4355: Play with sequence
调了好久,还是黑盒测试有前途 我以前怕不是学了假的吉利线段树(我第一次知道还要记次小值去更新的........) #include<cstdio> #include<algorith ...
- java中,为什么char类型数组可以直接用数组名打印,打印结果居然不是地址值!
char类型的数组就相当于一个字符串. 因为输出流System.out是PrintStream对象,PrintStream有多个重载的println方法,其中一个就是public void print ...
- Objective-C中的一些特殊的数据类型
nil nil和C语言的NULL相同,在objc/objc.h中定义.nil表示一个Objctive-C对象,这个对象的指针指向空(没有东西就是空). Nil 首字母大写的Nil和nil有一点不一样 ...
- 元类相关(type & metaclass)
metaclass作用: 1) 拦截类的创建 2) 修改类 3) 返回修改之后的类 """为什么要用metaclass类而不是函数? 由于__metaclass__可以接 ...
- [python学习篇] uiautomator xiaocong
Skip to content This repository Pull requests Issues Marketplace Gist Sign out Watch103 ...
- 【转】Unicode utf8等编码类型的原理
原文地址http://www.cnblogs.com/daxiong2014/p/4768681.html Unicode utf8等编码类型的原理 1.ASCII码 我们知道,在计算机内部,所有的 ...