首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

hdu4203 Doubloon Game-sg 击表找规律

2012-09-27 
hdu4203Doubloon Game-------sg打表找规律Doubloon GameTime Limit: 2000/1000 MS (Java/Others)Memory Li

hdu4203 Doubloon Game-------sg 打表找规律

Doubloon GameTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 223    Accepted Submission(s): 136


Problem Description
An old favorite of the pirates is a game for two players featuring one stack of coins. In turn, each player takes a number of coins from the stack. The number of coins that a player takes must be a power of a given integer K (1, K, K^2, etcetera). The winner is the player to take the last coin(s).
Can you help the pirates gure out how the player to move can win in a given game situation?InputOutputSample InputSample OutputSourceRecommend#include<iostream>#include<cstdlib>#include<stdio.h>#include<memory.h>#define ll __int64using namespace std;int b,minmin;ll fibo[110];bool flag;int dfs(int x){ if(x<0) return 0; for(int i=0;i<16;i++) { if(x-fibo[i]<0) break; if(dfs(x-fibo[i])==0) { return 1; } } return 0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&b); minmin=9999999; flag=true; fibo[0]=1; for(int i=1;i<=15;i++) fibo[i]=fibo[i-1]*b; for(int a=0;a<=10;a++) { if(dfs(a)) { for(int i=0;i<=15;i++) { if(a-fibo[i]>=0&&dfs(a-fibo[i])==0) { printf("%d ",fibo[i]); break; } } } else printf("0 "); } puts(""); }}
A题代码:#include<iostream>#include<cstdlib>#include<stdio.h>using namespace std;int main(){ int t,a,b; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); int x=a%(b+1); if(b&1) { if(x%2==0) puts("0"); else puts("1"); } else { if(x<b) { if(x%2==1) puts("1");else puts("0"); } else printf("%d\n",b); } }}

热点排行