BZOJ 1854: [Scoi2010]游戏 二分图匹配

来源:互联网 发布:80端口打不开 编辑:程序博客网 时间:2024/05/18 03:15

1854: [Scoi2010]游戏

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


解法一眼秒杀,然后。。。。

wa wa wa re re re tle tle tle。。。。。我知道了 这个东西是可以用时间戳优化的 不要每次都清标记

我也是醉了。。。匈牙利算法就没一遍写对过。。。。

属性点向武器连边


#include<cmath>#include<ctime>#include<cstdio>#include<cstdlib>#include<cstring>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<queue>#include<set>#include<map>using namespace std;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return f*x;}const int N=1010100;int n,m,ecnt,last[N],match[N],cur[N];struct EDGE{int to,nt;}e[N<<4];inline void add(int u,int v){e[++ecnt]=(EDGE){v,last[u]};last[u]=ecnt;}bool hungary(int u){for(int i=last[u];i;i=e[i].nt)if(cur[e[i].to]!=i){cur[e[i].to]=i;if(!match[e[i].to]||hungary(match[e[i].to])){match[e[i].to]=u;return 1;}}return 0;}int main(){m=read();int u,v; for(int i=1;i<=m;i++){u=read();v=read();add(u+m,i);add(v+m,i);n=max(u,n),n=max(v,n);}int ans=0;for(int i=1+m;i<=m+n;i++){if(!hungary(i)){printf("%d\n",ans);return 0;}ans++;}printf("%d\n",ans);return 0;} 


阅读全文
0 0