1854: [Scoi2010]游戏
Time Limit: 5 Sec Memory Limit: 162 MB
Submit: 3412 Solved: 1258
[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
【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
Source
Day1
二分图匹配裸题。。
也可以用并查集来做。。
并查集写法等到以后更新。。
安利黄学长并查集写法:
http://hzwer.com/2950.html
#include<cstdio>
#include<cstring>
using namespace std;
int n,i,head[1000001],cnt=1,part[1000001],t=0,a[1000001];
struct node
{
int next,to;
};
node edge[2000001];
int read()
{
int w=0,c=1;
char ch=getchar();
while (ch<'0' || ch>'9')
{
if (ch=='-')
c=-1;
ch=getchar();
}
while (ch>='0' && ch<='9')
{
w=w*10+ch-'0';
ch=getchar();
}
return w*c;
}
void add(int u,int v)
{
cnt++;
edge[cnt].next=head[u];
head[u]=cnt;
edge[cnt].to=v;
}
bool find(int s)
{
int k;
for (k=head[s];k;k=edge[k].next)
{
if (a[edge[k].to]==t)
continue;
a[edge[k].to]=t;
if (!part[edge[k].to] || find(part[edge[k].to]))
{
part[edge[k].to]=s;
return true;
}
}
return false;
}
int main()
{
int x,y,ans=0;
memset(head,0,sizeof(head));
memset(part,0,sizeof(part));
n=read();
for (i=1;i<=n;i++)
{
x=read();
y=read();
add(x,i);
add(y,i);
}
for (i=1;i<=10001;i++)
{
t++;
if (!find(i))
{
ans=i-1;
break;
}
}
printf("%d",ans);
return 0;
}