HDU 2147 kiki's game

本文通过实例展示了如何使用打表法与深度优先搜索(DFS)算法解决特定问题,详细探讨了算法实现过程及应用效果。

 

这个题我是打表出来的,

达标代码如下:

View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<queue>
 7 #include<set>
 8 #include<map>
 9 #include<vector>
10 using namespace std;
11 int d[3][2] = {0,-1,1,0,1,-1};
12 int n , m;
13 bool DFS( int x, int y )
14 {
15     for( int i = 0 ; i < 3; i ++ )
16     {
17         int dx = x +  d[i][0] , dy = y + d[i][1];
18         if( dy <= 0 || dx > n) continue;  
19         bool temp = DFS( dx ,dy );
20 
21         if( temp == false ) return true;  
22     }     
23     return false;
24 }
25 int main(  )
26 {
27     for( int i = 1 ; i <= 20; i ++ )
28     {
29       for( int  j = 1 ; j <= 10 ; j ++ )
30       {
31          n = i ; m = j ;
32          printf( "%d %d ",n , m ); 
33          printf( "%d\n",DFS( 1 , m ) );
34             
35       }
36     getchar(); 
37     }
38     system( "pause" );
39     return 0;
40 }
View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<queue>
 7 #include<set>
 8 #include<map>
 9 #include<vector>
10 using namespace std;
11 
12 int main(  )
13 {
14     int n , m ;
15     while( scanf( "%d %d",&n,&m ),n||m )
16     {
17        if( (n&1)&& (m&1) ) puts( "What a pity!" );
18        else puts( "Wonderful!" );       
19     }
20     //system( "pause" );
21     return 0;
22 }

 

转载于:https://www.cnblogs.com/bo-tao/archive/2012/04/19/2458078.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值