题目描述

lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备的某一个属性。并且每种装备最多只能使用一次。游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个属性值为3的装备攻击boss……以此类推。现在lxhgww想知道他最多能连续攻击boss多少次?

输入输出格式

输入格式:

输入的第一行是一个整数N,表示lxhgww拥有N种装备接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值

输出格式:

输出一行,包括1个数字,表示lxhgww最多能连续攻击的次数。

输入输出样例

输入样例#1:
复制

3
1 2
3 2
4 5
输出样例#1: 复制

2

说明

Limitation

对于30%的数据,保证N < =1000

对于100%的数据,保证N < =1000000

来源:SCOI 2010

二分图匹配;

对于第 i 种的两个属性 a,b;

连边 <a,i>,<b,i>;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ struct node {
int u, v, w;
int nxt;
}edge[maxn<<4];
bool vis[maxn>>1];
int head[maxn>>1];
int match[maxn << 3];
int tot;
void addedge(int x, int y) {
edge[++tot].u = x; edge[tot].v = y;
edge[tot].nxt = head[x]; head[x] = tot;
} bool dfs(int x) {
if (vis[x])return false;
vis[x] = 1;
for (int i = head[x]; i; i = edge[i].nxt) {
int v = edge[i].v;
if (!match[v] || dfs(match[v])) {
match[v] = x; return true;
}
}
return false;
} int main() {
//ios::sync_with_stdio(0);
int n;
rdint(n);
for (int i = 1; i <= n; i++) {
int x, y; rdint(x); rdint(y);
addedge(x, i); addedge(y, i);
}
int ans = 0;
for (int i = 1; i <= 10001; i++) {
ms(vis);
if (dfs(i))ans++;
else break;
}
cout << ans << endl;
return 0;
}

最新文章

  1. log4j.properties 详解与配置步骤(转)
  2. 洛谷 P1014 Cantor表 Label:续命模拟QAQ
  3. Linux Modules Introduction
  4. java 学习资料
  5. Posting data to a HttpHandler greater then ~29MB gives a 404 error
  6. win2008 ent r2 开启端口
  7. cf C. Dominoes
  8. IE6-BUG-CSS兼容详解
  9. UML六种关系
  10. 树上操作[HAOI 2015]
  11. Android_内部文件读取
  12. Python 有道翻译 爬虫 有道翻译API 突破有道翻译反爬虫机制
  13. bzoj千题计划299:bzoj1856: [Scoi2010]字符串
  14. 使用JMeter进行RESTful API测试
  15. HDU.5730.Shell Necklace(分治FFT)
  16. CentOS 安装Mosquitto及测试
  17. 使用gitlab, jenkins搭建CI(持续集成)系统(2) -- 配置webhook触发构建
  18. 【信息安全】MD5加密浅析
  19. 「Python」python与微信
  20. java 使用idea将工程打成jar并创建成exe文件类型执行

热门文章

  1. 前端多媒体(7)—— 在浏览器中实现rtmp推流
  2. poj-1379 Run Away(模拟退火算法)
  3. hdu-5640 King&#39;s Cake (水题)
  4. 【leetcode刷题笔记】Path Sum
  5. 常用调试工具gdb,dbx,valgrind介绍一
  6. 树套树Day2
  7. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
  8. 转 Django根据现有数据库,自动生成models模型文件
  9. IntelliJ手记
  10. 深入理解javascript中的立即执行函数