HDU 2177 取(2堆)石子游戏

这题就是对http://acm.hdu.edu.cn/showproblem.php?pid=1527的扩充

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          int k = m - n;

18          int step = ( int )( k * ( 1 + sqrt( 5 ) )/2.0 );

19          if( step != n )

20          {

21              puts( "1" );

22              for( int i = 1 ; i <=n  ; i++ )

23              {

24                   int nn = n - i, mm = m - i;

25           //        k = mm - nn;

26         //          int t = ( int )( k * ( 1 + sqrt( 5 ) )/2.0 );

27         //          printf( "t==%d nn==%d\n",t , nn );

28                   if(  step == nn  )

29                   {

30                      printf( "%d %d\n",nn , mm );    

31                   }

32                      

33              }

34              for( int i = m -1  ; i >=0 ; i -- )

35              {

36                  int t = n , tt = i;

37                  if( t > tt )

38                  {

39                     t ^= tt;

40                     tt ^= t;

41                     t ^= tt;

42                  }

43                  k = tt - t;

44                  step = ( int )( k * ( 1 + sqrt( 5 ) )/2.0 );

45                  if( step == t ) 

46                   printf( "%d %d\n",t , tt);     

47              }    

48          }

49          else printf( "0\n" ) ;      

50      }

51     //system( "pause" );

52     return 0;

53 }

 

这里就不多说了,直接看代码吧;

你可能感兴趣的:(HDU)