zoukankan      html  css  js  c++  java
  • HDU1181 变形课 DFS

      简单DFS,代码如下:

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    
    char word[10000][100];
    
    int hash[10000];
    
    void DFS( char *w, int cnt, int &ans )
    {
    	if( w[ strlen( w )- 1 ]== 'm' )
    	{
    		ans= 1;
    		return;
    	}
    	for( int i= 0; i< cnt; ++i )
    	{
    		if( !hash[i]&& word[i][0] == w[ strlen( w )- 1 ]  )
    		{
    			hash[i]= 1;
    		    DFS( word[i], cnt, ans );
    		}
    	}
    }
    
    int main(  )
    {
    	int k= 0;
    	while( scanf( "%s", word[k++] )!= EOF )
    	{
    		while( scanf( "%s", word[k++] ), word[k- 1][0]!= '0' ) ;
    		int cnt= k,ans= 0;
    		k= 0;
    		memset( hash, 0, sizeof( hash ) );
    		for( int i= 0; i< cnt; ++i )
    		{
    			if( word[i][0]== 'b'&& !ans )
    			{
    				DFS( word[i], cnt, ans );
    			}
    		}
    		printf( ans? "Yes.\n": "No.\n" );
    	}
    	return 0;
    }
    
  • 相关阅读:
    7、shell函数
    5、shell分支
    6、shell循环
    4、shell中的test命令
    3、shell中引号
    2、shell变量
    1、建立和运行shell
    awk命令简介
    18、异步IO
    Python模块:sys
  • 原文地址:https://www.cnblogs.com/Lyush/p/2135123.html
Copyright © 2011-2022 走看看