• HDU2063_过山车_C++


      题目:http://acm.hdu.edu.cn/showproblem.php?pid=2063

      又是一道二分图匹配的裸题,直接上匈牙利算法

      注意一点它末尾的0结束,是标志着有多组数据……坑……

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<ctime>
     8 #include<queue>
     9 #define fre(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
    10 #define Test1 freopen("in.in","r",stdin);freopen("1.out","w",stdout)
    11 #define Test2 freopen("in.in","r",stdin);freopen("2.out","w",stdout)
    12 using namespace std;
    13 typedef long long LL;
    14 typedef double db;
    15 const double CPS=CLOCKS_PER_SEC,TL=0.98;
    16 const int oo=2147483647,N=501,M=1001;
    17 int first[N],Next[M],v[M],g[N];
    18 bool f[N];
    19 inline bool xyl(int x)
    20 {
    21     int i,k;
    22     for (i=first[x];i;i=Next[i])
    23     {
    24         k=v[i];
    25         if (f[k])
    26         {
    27             f[k]=0;
    28             if ((!g[k])||xyl(g[k]))
    29             {
    30                 g[k]=x;
    31                 return 1;
    32             }
    33         }
    34     }
    35     return 0;
    36 }
    37 int main()
    38 {
    39     int n,na,nb,i,j,ans,x;
    40     scanf("%d",&n);
    41     while (n)
    42     {
    43         ans=0;
    44         scanf("%d%d",&na,&nb);
    45         for (i=1;i<=na;i++) first[i]=0;
    46         for (i=1;i<=nb;i++) g[i]=0;
    47         for (i=1;i<=n;i++)
    48         {
    49             scanf("%d%d",&x,&v[i]);
    50             Next[i]=first[x];
    51             first[x]=i;
    52         }
    53         for (i=1;i<=na;i++)
    54         {
    55             for (j=1;j<=nb;j++) f[j]=1;
    56             if (xyl(i)) ans++;
    57         }
    58         printf("%d
    ",ans);
    59         scanf("%d",&n);
    60     }
    61     return 0;
    62 } 

    版权所有,转载请联系作者,违者必究

    联系方式:http://www.cnblogs.com/hadilo/p/5932395.html

  • 相关阅读:
    MVC总结
    HTML+CSS总结
    常用正则表达式
    从你的全世界切过(胡说八道支持向量机SVM小故事)
    Beta分布
    贝叶斯决策理论
    Linux(Ubuntu)下载安装破解Matlab2016
    贝叶斯规则
    多元分布
    条件分布
  • 原文地址:https://www.cnblogs.com/hadilo/p/6067094.html
Copyright © 2020-2023  润新知