[BZOJ1854][SCOI2010]游戏 二分图最大匹

1854: [Scoi2010]游戏

Time Limit: 5 Sec  Memory Limit: 162 MB
Submit: 5316  Solved: 2128
[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

3
1 2
3 2
4 5

Sample Output

2

HINT

【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000

Source

 
 
 
对于每一个武器,我们用它的伤害与武器编号连边,跑二分图最大匹配,与  [BZOJ1191][HNOI2006]超级英雄Hero  类似
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 using namespace std;
 8 struct data
 9 {
10     int to,next;
11 }e[2000005];
12 int head[1000005],cnt;
13 void add(int u,int v){e[cnt].next=head[u];e[cnt].to=v;head[u]=cnt;cnt++;}
14 int n,m;
15 int ans=0;
16 int vis[1000005];
17 int to[1000005];
18 int t=0;
19 bool find(int now)
20 {
21     for(int i=head[now];i>=0;i=e[i].next)
22         if(vis[e[i].to]!=t)
23         {
24             vis[e[i].to]=t;
25             if(!to[e[i].to]||find(to[e[i].to]))
26             {
27                 to[e[i].to]=now;
28                 return 1;
29             }
30         }
31     return 0;
32 }
33 int main()
34 {
35     memset(head,-1,sizeof(head));
36     scanf("%d",&n);
37     for(int i=1;i<=n;i++)
38     {
39         int a,b;
40         scanf("%d%d",&a,&b);
41         add(a,i);add(b,i);
42     }
43     for(int i=1;i<=10000;i++)
44     {
45         t++;
46         if(find(i)) ans++;
47         else break;
48     }
49     printf("%d",ans);
50 }
View Code
O(∩_∩)O~ (*^__^*) 嘻嘻…… O(∩_∩)O哈哈~
原文地址:https://www.cnblogs.com/wls001/p/7348924.html