zoukankan      html  css  js  c++  java
  • hoj 2472 IRLab

    /*

    题目:

           值班问题,给出所有人的空余时间,问能不能够在每一个时间里安排一个人值班

    分析:

           二分匹配问题,按人与他的空余时间连线构图,然后就是hungry算法了,简单

    */

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    using namespace std;

    #define X 22

    bool g[X][X],use[X];

    int xm[X],ym[X],k,p;

    bool dfs(int u)

    {

           for(int v=0;v<k;v++)

                  if(g[u][v]&&!use[v])

                  {

                         use[v] = true;

                         if(ym[v]==-1||dfs(ym[v]))

                         {

                                xm[u] = v;

                                ym[v] = u;

                                return true;

                         }

                  }

                  return false;

    }

    int hungry()

    {

           int ret = 0;

           memset(xm,-1,sizeof(xm));

           memset(ym,-1,sizeof(ym));

           for(int u=0;u<p;u++)

                  if(xm[u]==-1)

                  {

                         memset(use,false,sizeof(use));

                         if(dfs(u))

                                ret++;

                  }

                  return ret;

    }

    int main()

    {

           freopen("sum.in","r",stdin);

           freopen("sum.out","w",stdout);

           while(cin>>k>>p,k||p)

           {

                  int t,x;

                  memset(g,false,sizeof(g));

                  for(int i=0;i<p;i++)

                  {

                         scanf("%d",&t);

                         while(t--)

                         {

                                scanf("%d",&x);

                                g[i][x] = true;//该人与他的空余时间连通

                         }

                  }

                  if(hungry()==k)                 //如果能够安排好的话

                         printf("yes\n");

                  else

                         printf("no\n");

                  //printf("%d\n",hungry());

           }

           return 0;

    }

  • 相关阅读:
    POJ 1556 The Doors (未完)
    setblendstate & setdepthstencilstate
    transparent 的新问题
    texCUBE() to CubemapSampler.Sample()
    error: The shader requires a sampler in slot 0 which hasn't been set [XXXsampler]
    error X3025:global variables are implicitly constant, enable compatibility mode to allow modification
    MSAA
    check environment var
    setDepthStencilState
    sampler state
  • 原文地址:https://www.cnblogs.com/yejinru/p/2436081.html
Copyright © 2011-2022 走看看