zoukankan      html  css  js  c++  java
  • bzoj1191: [HNOI2006]超级英雄Hero

    二分图最大匹配就可以了

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    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=1005;
    const int maxn=3005;
    const int inf=0x7f7f7f7f;
    struct edge{
        int to;edge *next;
    };
    edge es[maxn],*pt=es,*head[nmax];
    void add(int u,int v,int d){
        pt->to=v;pt->next=head[u];head[u]=pt++;
        pt->to=d;pt->next=head[u];head[u]=pt++;
    }
    bool vis[nmax];int match[nmax];
    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(),m=read(),u,v;
        rep(i,1,m) u=read()+1,v=read()+1,add(i,u,v);
        int ans=0;
        rep(i,1,m){
            clr(vis,0);
            if(dfs(i)) ans++;
            else break;
            //rep(j,1,n) printf("%d ",match[j]);printf("
    ");
        }
        printf("%d
    ",ans);
        return 0;
    }
    
    

      

    1191: [HNOI2006]超级英雄Hero

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 3535  Solved: 1649
    [Submit][Status][Discuss]

    Description

    现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金。主持人问题准备了若干道题目,只有当选手正确回答一道题后,才能进入下一题,否则就被淘汰。为了增加节目的趣味性并适当降低难度,主持人总提供给选手几个“锦囊妙计”,比如求助现场观众,或者去掉若干个错误答案(选择题)等等。 这里,我们把规则稍微改变一下。假设主持人总共有m道题,选手有n种不同的“锦囊妙计”。主持人规定,每道题都可以从两种“锦囊妙计”中选择一种,而每种“锦囊妙计”只能用一次。我们又假设一道题使用了它允许的锦囊妙计后,就一定能正确回答,顺利进入下一题。现在我来到了节目现场,可是我实在是太笨了,以至于一道题也不会做,每道题只好借助使用“锦囊妙计”来通过。如果我事先就知道了每道题能够使用哪两种“锦囊妙计”,那么你能告诉我怎样选择才能通过最多的题数吗?

    Input

    输入文件的一行是两个正整数n和m(0 < n <1001,0 < m < 1001)表示总共有n中“锦囊妙计”,编号为0~n-1,总共有m个问题。
    以下的m行,每行两个数,分别表示第m个问题可以使用的“锦囊妙计”的编号。
    注意,每种编号的“锦囊妙计”只能使用一次,同一个问题的两个“锦囊妙计”可能一样。

    Output

    第一行为最多能通过的题数p

    Sample Input

    5 6
    3 2
    2 0
    0 3
    0 4
    3 2
    3 2

    Sample Output

    4

    HINT

     

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    随便练习的进制转换
    回顾快速排序
    常用c++函数
    POJ 1163 The Triangle
    HDU 1155 Bungee Jumping
    ZOJ 3861 Valid Pattern Lock
    POJ 1273 Drainage Ditches
    Hrbust 2240 土豪的时代
    POJ 3468 A Simple Problem with Integers
    POJ 1061 青蛙的约会
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5859401.html
Copyright © 2011-2022 走看看