zoj 1913 || poj 2348Euclid's Game

    技术2025-08-24  48

    我开始模拟了半天,搜索神马的。。。MEL 了。。。搜了下,发现有牛叉的想法。。。

     

    http://hi.baidu.com/justlyn/blog/item/d6fa501f0a0edf0c304e150e.html

     

    这个蛮好理解的。。。

     

    无论怎么减,最后几个状态是确定的(最后几个状态没人只有唯一的减法),所以只要根据谁能让自己能达到必胜的那个状态即可。

     

    #include <cstdio> #include <cstdlib> #include <iostream> #include <string.h> #include <queue> #include <limits.h> using namespace std; int main() { int a,b,ans; while( ~scanf("%d%d",&a,&b) ) { if( a == b && a == 0 ) break; ans = 0; if( a == 0 || b == 0 || a == b ) goto end; while(1) { if ( a < b ) swap(a,b); if( a / b == 1 ) { ans++; a -= b; continue; } if( a / b > 1 ) break; if( a == 0 || b == 0 ) break; } end: if( ans % 2 == 0 ) printf("Stan wins/n"); else printf("Ollie wins/n"); } return 0; }  

    最新回复(0)