HDU 1729 Stone Game

刚开始这不知道思路,后来还是看了别人的解题报告才弄出来;

集体思路:当前的箱子容量为si,那么要赢就要满足t + t*t < si

现在箱子本来有ci:

ci > t 则必胜;

ci == t 则必败;

ci < t   不能断定输赢,那么就要继续调用SG函数;

如果 ci > t SG值就是ci - t;因为剩下的容量只有这么大了;

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 Getsg( int s , int c )
12 {
13     int t = (int)sqrt( s );
14     while( t + t*t >= s )
15            t --;
16     if( t < c )  return s - c;
17     else return Getsg( t , c );    
18 }
19 int main(  )
20 {
21     int n,s,c,Case=1;
22     while( scanf( "%d",&n ) , n )
23     {
24         int t = 0;
25         for( int i = 0; i < n ; i++ )
26         {
27             scanf( "%d %d",&s , &c );
28             t ^= Getsg( s , c );
29         }
30         printf( "Case %d:\n",Case++ );
31         if( t == 0 ) puts( "No" );
32         else puts( "Yes" );        
33     }
34     //system( "pause" );
35     return 0;
36 }

 

posted @ 2012-04-22 21:02  wutaoKeen  阅读(244)  评论(0编辑  收藏  举报