[BZOJ]1854 [SCOI]2010 游戏
2017-09-11 18:07
507 查看
1854: [Scoi2010]游戏
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 5451 Solved: 2196
[Submit][Status][Discuss]
Description
lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备的某一个属性。并且每种装备最多只能使用一次。 游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个属性值为3的装备攻击boss……以此类推。现在lxhgww想知道他最多能连续攻击boss多少次?
Input
输入的第一行是一个整数N,表示lxhgww拥有N种装备 接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值Output
输出一行,包括1个数字,表示lxhgww最多能连续攻击的次数。Sample Input
31 2
3 2
4 5
Sample Output
2HINT
【数据范围】对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
Source
Day1[Submit][Status][Discuss]
HOME Back
可以去看hzwer学长的讲解...我就不班门弄斧了, 但是注意他的程序有误, 在uni的时候要判断一下那个权值低的有没有被vis过, vis过了就要把大的赋成true.
#include<stdio.h> #include<algorithm> #define Mercer register int using namespace std; const int maxn = 1e4 + 5; int fa[maxn], n; bool vis[maxn]; inline const int read(){ register int x = 0; register char ch = getchar(); while(ch < '0' || ch > '9') ch = getchar(); while(ch >= '0' && ch <= '9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar(); return x; } int find(int x){return (fa[x] == x) ? x : fa[x] = find(fa[x]);} inline void uni(int p, int q){ if(p > q) swap(p, q); (vis[p]) ? vis[q] = true : vis[p] = true; fa[p] = q; } int main(){ n = read(); for(Mercer i = 1; i <= 10000; ++i) fa[i] = i; for(Mercer i = 1; i <= n; ++i){ int p = read(), q = read(); p = find(p), q = find(q); if(p == q) vis[p] = true; else uni(p, q); } for(Mercer i = 1; i <= n + 1; ++i) if(!vis[i]) {printf("%d\n", i-1); break;} return 0; }
相关文章推荐
- BZOJ 1854|SCOI 2010|游戏|并查集
- 【BZOJ 1854】 [Scoi2010]游戏
- BZOJ1854 [Scoi2010]游戏
- bzoj1854 [Scoi2010]游戏
- BZOJ 1854: [Scoi2010]游戏 二分图匹配or并查集
- bzoj1854 [Scoi2010]游戏
- BZOJ 1854: [Scoi2010]游戏
- bzoj1854: [Scoi2010]游戏
- AC日记——[SCOI2010]游戏 bzoj 1854
- [bzoj1854][Scoi2010]游戏
- BZOJ 1854 [Scoi2010] 游戏 题解与分析
- BZOJ1854 [Scoi2010]游戏(并查集/二分图匹配)
- [bzoj1854][Scoi2010]游戏
- BZOJ 1854 SCOI2010 游戏 二分图最大匹配/并查集
- 【bzoj1854】[Scoi2010]游戏
- bzoj 1854: [Scoi2010]游戏(二分图的最大匹配)
- bzoj 1854: [Scoi2010]游戏【匈牙利算法】
- [BZOJ1854][Scoi2010]游戏
- 【bzoj1854】[Scoi2010]游戏
- BZOJ1854:[SCOI2010]连续攻击游戏——题解