hdu 3729

Posted 发牌员

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 3729相关的知识,希望对你有一定的参考价值。

二分图匹配,应该叫匈牙利算法,以前做过这种题,看明白了思想,板子忘了,无奈只能看白书上的板子,这个板子有点乱,比如1,2,3匹配1,2,3就会乱匹配,建议还是去网上学学好的板子,这里我用x和N+X区分了匹配项

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=100000+10;
vector<int> G[2*maxn];
int match[maxn*2];
bool used[maxn*2];
int n,t;
bool dfs(int v)
{
     used[v]=true;
    for(int i=0;i<G[v].size();i++)
    {
        int u=G[v][i],w=match[u];
        if(w<0||!used[w]&&dfs(w))
        {
            match[u]=v;
            match[v]=u;
            return true;
        }
    }
    return false;
}
int main()
{
     scanf("%d",&t);
   while(t--)
   {
       for(int i=1;i<=n;i++)
        G[i].clear();
       scanf("%d",&n);
       for(int i=1;i<=n;i++)
       {
              int a,b;
             scanf("%d%d",&a,&b);
             a=100000+a;//区分匹配项
             b=100000+b;
            for(int j=a;j<=b;j++)
            {
                G[i].push_back(j);
                G[j].push_back(i);
            }
       }
       int res=0;
       int cc[70];
         memset(match,-1,sizeof(match));
          for(int i=n;i>=1;i--)
          {
              if(match[i]<0)
              {
                  memset(used,0,sizeof(used));
                  if(dfs(i))
                  {
                      cc[res]=i;
                      res++;
                  }

              }
          }
        sort(cc,cc+res);
        printf("%d\n",res);
        for(int i=0;i<res;i++)
        {
            if(i) printf(" ");
            printf("%d",cc[i]);
        }
      printf("\n");
   }
    return 0;
}

 

以上是关于hdu 3729的主要内容,如果未能解决你的问题,请参考以下文章

HDU-3729 二分匹配 匈牙利算法

HDU - 3729 I'm Telling the Truth(二分匹配)

I'm Telling the TruthHDU - 3729 匈牙利算法,DFS

codevs 3729 飞扬的小鸟 x

poj3729后缀数组

[codevs3729]飞扬的小鸟