• BZOJ-1191 [HNOI2006]超级英雄Hero(二分图匹配)


    1191: [HNOI2006]超级英雄Hero

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 3837  Solved: 1767
    [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

    原来BZOJ上也是有水题的ovo,不过他说必须答出这题才能答下一题,所以我就智障的被坑了ovo

     1 #include "bits/stdc++.h"
     2 #define mem(a,b) memset(a,b,sizeof(a))
     3 using namespace std;
     4 typedef long long LL;
     5 const int MAX=3005;
     6 int n,m,K,tot;
     7 int head[MAX],adj[MAX],next[MAX],cy[MAX];
     8 bool vis[MAX];
     9 void addedge(int u,int v){
    10     tot++;
    11     adj[tot]=v;
    12     next[tot]=head[u];
    13     head[u]=tot;
    14 }
    15 void init(){
    16     int i,j,x,y;
    17     scanf("%d%d",&K,&n);
    18     mem(head,0),mem(cy,-1);
    19     for (i=1;i<=n;i++){
    20         scanf("%d%d",&x,&y);
    21         ++x,++y;
    22         addedge(i,x);
    23         addedge(i,y);
    24     }
    25 }
    26 int dfs(int x){
    27     int i,j,v;
    28     for (i=head[x];i;i=next[i]){
    29         v=adj[i];
    30         if (!vis[v]){
    31             vis[v]=true;
    32             if (cy[v]==-1 || dfs(cy[v])){
    33                 cy[v]=x;
    34                 return 1;
    35             }
    36         }
    37     }
    38     return 0;
    39 }
    40 int main(){
    41     freopen ("hero.in","r",stdin);
    42     freopen ("hero.out","w",stdout);
    43     int i,j;
    44     init();
    45     for (i=1;i<=n;i++){
    46         mem(vis,false);
    47         if (!dfs(i)) break;
    48     }
    49     printf("%d",i-1);
    50     return 0;
    51 }
    标程 is locked
    未来是什么样,未来会发生什么,谁也不知道。 但是我知道, 起码从今天开始努力, 肯定比从明天开始努力, 要快一天实现梦想。 千里之行,始于足下! ——《那年那兔那些事儿》
  • 相关阅读:
    [Chapter 3 Process]Practice 3.4 Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.
    [Chapter 3 Process]Practice 3.3 Discuss three major complications that concurrent processing adds to an operating system.
    爬取:中国大学排名
    基础统计学--复习
    pandas之数据结构
    numpy之初探排序和集合运算
    numpy之统计函数和布尔数组方法
    numpy之meshgrid和where
    numpy之通用函数ufunc
    numpy之转置(transpose)和轴对换
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/6054138.html
Copyright © 2020-2023  润新知