标签:des style blog http color java os io strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2074 Accepted Submission(s): 924
1 #include<cstring> 2 #include<cstdio> 3 bool flag=false; 4 int cont=1; 5 void botree(int n,int m){ 6 if(n<m)n^=m^=n^=m; 7 if(n%m) 8 for(int i=1;i*m<n;i++){ 9 cont++; 10 botree(n-i*m,m); 11 } 12 else { 13 if(cont&1) flag=true; 14 cont=1; 15 } 16 } 17 int main(){ 18 int n,m; 19 //freopen("test.in","r",stdin); 20 while(scanf("%d%d",&n,&m),n+m){ 21 flag=false; 22 botree(n,m); 23 if(flag) printf("Stan wins\n"); 24 else printf("Ollie wins\n"); 25 } 26 return 0; 27 }
然后进行了优化之后.....得到这样的代码:
1 /*Problem : 1525 ( Euclid‘s Game ) Judge Status : Accepted 2 RunId : 11528629 Language : C++ Author : huifeidmeng 3 Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta*/ 4 5 #include<cstring> 6 #include<cstdio> 7 bool flag=false; 8 int cont=1,cc=0; 9 void botree(int n,int m){ 10 if(n<m) n^=m^=n^=m; 11 if(m>0&&((n%m)&&n/m==1)){ 12 cont++; 13 botree(n%m,m); 14 } 15 else if(cont&1) flag=true; 16 } 17 int main(){ 18 int n,m; 19 //freopen("test.in","r",stdin); 20 while(scanf("%d%d",&n,&m),n+m){ 21 flag=false; 22 cont=1; 23 botree(n,m); 24 if(flag) printf("Stan wins\n"); 25 else printf("Ollie wins\n"); 26 } 27 return 0; 28 }
hdu------(1525)Euclid's Game(博弈决策树)
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/gongxijun/p/3931103.html