zoukankan      html  css  js  c++  java
  • hdu 1150【Machine Schedule】

    有时候都不太想写博客了,(~ o ~)~zZ

    这一题是纯粹的二分图匹配,不过要注意一点哈“At the beginning they are both work at mode_0”,所以要判断一下两点连接的时候是不是存在0这个点

    if(a && b)
       pro[a].push_back(b);

    代码如下:
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <vector>
     4 using namespace std;
     5 
     6 int vis[200];
     7 int link[200];
     8 vector<int> pro[200];
     9 int n,m,k;
    10 
    11 void init()
    12 {
    13     memset(link,-1,sizeof(link));
    14     for(int i = 0;i < n;i ++)
    15     {
    16         pro[i].clear();
    17     }
    18 }
    19 
    20 bool can(int x)
    21 {
    22     int len = pro[x].size();
    23     for(int i = 0;i < len;i ++)
    24     {
    25         int t = pro[x].at(i);
    26         if(!vis[t])
    27         {
    28             vis[t] = 1;
    29             if(link[t] == -1 || can(link[t]))
    30             {
    31                 link[t] = x;
    32                 return true;
    33             }
    34         }
    35     }
    36 
    37     return false;
    38 }
    39 
    40 int maxmatch()
    41 {
    42     int num = 0;
    43     for(int i = 0;i < n;i ++)
    44     {
    45         memset(vis,0,sizeof(vis));
    46         if(can(i))
    47         {
    48             num ++;
    49         }
    50     }
    51 
    52     return num;
    53 }
    54 
    55 int main()
    56 {
    57     while(scanf("%d",&n),n)
    58     {
    59         scanf("%d%d",&m,&k);
    60 
    61         init();
    62         for(int i = 0;i < k;i ++)
    63         {
    64             int index,a,b;
    65             scanf("%d%d%d",&index,&a,&b);
    66             if(a && b)
    67             pro[a].push_back(b);
    68         }
    69 
    70         printf("%d\n",maxmatch());
    71     }
    72 
    73     return 0;
    74 }
  • 相关阅读:
    05-3. 六度空间 (PAT)
    05-2. Saving James Bond
    05-1. List Components (PAT)
    04-3. Huffman Codes (PAT)
    04-2. File Transfer (PAT)
    04-1. Root of AVL Tree (PAT)
    03-3. Tree Traversals Again (PAT)
    03-2. List Leaves (PAT)
    03-1. 二分法求多项式单根(PAT)
    CDH Namenode自动切换(active-standby)
  • 原文地址:https://www.cnblogs.com/Shirlies/p/2494142.html
Copyright © 2011-2022 走看看