bzoj1854: [Scoi2010]游戏

二分图最大匹配就可以了

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define qwq(x) for(edge *o=head[x];o;o=o->next)
int read(){
    int x=0;char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-'0',c=getchar();
    return x;
}
const int nmax=10005;
const int maxn=1000005;
struct edge{
    int to;edge *next;
};
edge es[maxn<<1],*pt=es,*head[nmax];
void add(int u,int v,int d){
    pt->to=d;pt->next=head[u];head[u]=pt++;
    pt->to=d;pt->next=head[v];head[v]=pt++;
}
bitset<maxn>vis;int match[maxn];
bool dfs(int x){
    qwq(x) if(!vis[o->to]){
        vis[o->to]=1;
        if(!match[o->to]||dfs(match[o->to])){
            match[o->to]=x;return true;
        }
    }
    return false;
}
int main(){
    int n=read(),u,v;
    rep(i,1,n) u=read(),v=read(),add(u,v,i);
    int ans=0;
    rep(i,1,n) {
        vis.reset();
        if(dfs(i)) ans++;
        else break;
    }
    printf("%d\n",ans);
    return 0;
}

  

1854: [Scoi2010]游戏

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

[Submit][Status][Discuss]
posted @ 2016-09-10 14:41  BBChq  阅读(118)  评论(0编辑  收藏  举报