BZOJ 1854: [Scoi2010]游戏 并查集
1854: [Scoi2010]游戏
Time Limit: 5 Sec Memory Limit: 162 MB
Submit: 2672 Solved: 958
[Submit][Status][Discuss]
Description
最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使
用该装备的某一个属性。并且每种装备最多只能使用一次。
游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生
伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个
属性值为3的装备攻击boss……以此类推。
现在lxhgww想知道他最多能连续攻击boss多少次?
Input
接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值
Output
Sample Input
1 2
3 2
4 5
Sample Output
HINT
【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
题解
一个武器可以看成连接对应两个属性值的一条边
可以证明如果一个联通块中出现一个环
则整个联通块都可以取
否则会有一个点不能取
显然这个不取的点是最大的那个点= =
然后扫一遍看能取到哪就行了
找环和维护最大可以用并查集做
//转载的,太神啦!!!!
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <vector>
#include <functional>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
typedef long double ld; const int maxn = ; int n, fa[maxn], is[maxn]; int getfa(int now)
{
return (!fa[now]) ? now : fa[now] = getfa(fa[now]);
} int main()
{
scanf("%d", &n);
for (int i = ; i < n; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
u = getfa(u), v = getfa(v);
if (u == v) is[u] = is[v] = ;
else
{
if (u < v)swap(u, v);
if (is[u] || is[v]) is[u] = is[v] = ;
fa[v] = u;
is[v] = ;
}
}
for (int i = ; i < maxn; ++i)
if (!is[i])
{
cout << i - ;
break;
}
}
BZOJ 1854: [Scoi2010]游戏 并查集的更多相关文章
- bzoj 1854: [Scoi2010]游戏 (并查集||二分图最大匹配)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 写法1: 二分图最大匹配 思路: 将武器的属性对武器编号建边,因为只有10000种 ...
- 1854: [Scoi2010]游戏[并查集]
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4938 Solved: 1948[Submit][Status] ...
- BZOJ 1854: [Scoi2010]游戏 无向图判环
题目链接: 题目 1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MB 问题描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装 ...
- BZOJ 1854: [Scoi2010]游戏( 二分图最大匹配 )
匈牙利算法..从1~10000依次找增广路, 找不到就停止, 输出答案. --------------------------------------------------------------- ...
- ●BZOJ 1854 [Scoi2010]游戏
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1854 题解: 并查集(还可以用匈牙利算法进行单路增广的二分图匹配) 把每个武器看成是一条边, ...
- BZOJ 1854: [Scoi2010]游戏(二分图匹配/并查集)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 题解: 1.二分图匹配: 首先我们发现每件装备只能在两种属性中选一种.因此,我们以每 ...
- BZOJ 1854: [Scoi2010]游戏 [连通分量 | 并查集 | 二分图匹配]
题意: 有$n \le 10^6$中物品,每种两个权值$\le 10^4$只能选一个,使得选出的所有权值从1递增,最大递增到多少 一开始想了一个奇怪的规定流量网络流+二分答案做法...然而我还不知道怎 ...
- 【bzoj1854】[Scoi2010]游戏 - 并查集
lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备最多只能使 ...
- bzoj 1854: [Scoi2010]游戏
#include<cstdio> #include<iostream> #include<cstring> #define M 2000008 using name ...
随机推荐
- Linux USB驱动学习总结(三)---- USB鼠标的加载、初始化和通信过程
1.usbmouse的定义:usb鼠标既包含usb设备(usb_device)的属性也包含input输入设备(input_dev)的属性 struct usb_mouse { ];///USB鼠标设备 ...
- Python基础之多线程事件Event
import threading,time class Boss(threading.Thread): def run(self): print("BOSS:伙计们今晚上加班到22:00&q ...
- C# 日文网址转punnycode
Uri uri = new Uri(url); IdnMapping idn = new IdnMapping();url= url.Replace(uri.Host, idn.GetAscii(ur ...
- 下一代Android打包工具,100个渠道包只需要10秒钟 https://github.com/mcxiaoke
https://github.com/mcxiaoke/packer-ng-plugin https://github.com/Meituan-Dianping/walle https://githu ...
- TCP包服务器接受程序
//功能:客户端发送TCP包,此程序接受到,将字母转换为大写,在发送到客户端#include <stdio.h>#include <sys/socket.h>#include ...
- Spring框架(管理事务)
Spring底层使用Transaction事物模板来进行操作.具体操作: 1.service 需要获得 TransactionTemplate 2.spring 配置模板,并注入给service 3. ...
- Java字符串拼接效率对比
1.来自:http://blog.csdn.net/Zen99T/article/details/51255418 2.来自:http://blog.csdn.net/kimsoft/article/ ...
- linux内核之accept实现
用户态对accept的标准用法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_size) ...
- 每位架构师都应该熟知的 10 个 SOA 设计模式
这 10 个 SOA 设计模式是如此之重要,其应用是如此之广泛,以至于它们都有些显而易见了. 1. 服务无关 服务无关实现对多种业务通用的逻辑.将服务无关的逻辑分离成离散的服务以方便服务的重用和整合. ...
- LeetCode699. Falling Squares
On an infinite number line (x-axis), we drop given squares in the order they are given. The i-th squ ...