HDU 2219(拓扑排序)

对于双方有意义的信息分别为日和月 当且仅当其入度为一存在时 才能继续进行游戏 否则必然无法判断出谁能获胜 另外要注意的是可能是生日不在表中的情况 以及

 

对重复日期的处理 具体参加wiskey大牛的解题报告 以下是实现代码

 

 

 

 

#include <iostream>
using namespace std;

bool hash[20][40];

long m_in[20];
long d_in[40];
int main()
{
    
long T;
    scanf(
"%ld",&T);
    
while (T--)
    {
        memset(hash,
0,sizeof(hash));
        memset(m_in,
0,sizeof(m_in));
        memset(d_in,
0,sizeof(d_in));
        
long N,M,D,i,j;
        scanf(
"%ld%ld%ld",&N,&M,&D);
        
while(N--)
        {
            
long mon,day;
            scanf(
"%ld%ld",&mon,&day);
            
if(!hash[mon][day])
            {
                hash[mon][day]
=true;
                
++m_in[mon];
                
++d_in[day];
            }
        }
        
        
if (!hash[M][D])
        {
l1:
            puts(
"No");
            
continue;
        }

        
bool win=false;
        
while(1)
        {
            
bool finish=false;
            
if (m_in[M]==1)
            {
                win
=true;
                
break;
            }

            
for (i=1;i<=12;++i)
            {
                
if (m_in[i]==1)
                {
                    finish
=true;
                    
for (j=1;j<=31;++j)
                    {
                        
if (hash[i][j])
                        {
                            
--d_in[j];
                            
--m_in[i];
                            hash[i][j]
=false;
                            
break;
                        }
                    }
                }

            }

            
if (d_in[D]==1)
            {
                
break;
            }

            
for (i=1;i<=31;++i)
            {
                
if (d_in[i]==1)
                {
                    finish
=true;
                    
for (j=1;j<=12;++j)
                    {
                        
if (hash[j][i])
                        {
                            
--d_in[i];
                            
--m_in[j];
                            hash[j][i]
=false;
                            
break;
                        }
                    }
                }
            }
            
if (!finish)
            {
                
goto l1;
            }
        }

        
if (win)
        {
            puts(
"Wiskey Win");
        }
        
else
        {
            puts(
"Michelle Win");
        }
    }
    
return 0;
}
posted @ 2008-09-04 20:42  Hdu-Lost  阅读(392)  评论(0编辑  收藏  举报