zoj 1827 The Game of 31
2012-09-09 22:27
295 查看
题目大意:有1-6种牌,每种 牌有四张,A先手,一个人出一张牌,当所有的牌加起来的和大于31,谁就输了
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=827
解题思路:首先知道,当总和等于31时,无论哪种组合都是比败点,所以,小于31的总和的每一种组合状态,
如果能靠加上某一张牌,就能将对手至于必败点,那这点就是必胜点
如果找不到这样一种转换,则该点为必败点,最只用根据他输得数据,
判断他是否为必败点即可,最多判断一下总和大于31的特殊情况就可以了!
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=827
解题思路:首先知道,当总和等于31时,无论哪种组合都是比败点,所以,小于31的总和的每一种组合状态,
如果能靠加上某一张牌,就能将对手至于必败点,那这点就是必胜点
如果找不到这样一种转换,则该点为必败点,最只用根据他输得数据,
判断他是否为必败点即可,最多判断一下总和大于31的特殊情况就可以了!
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<string> #include<vector> using namespace std; char s[10000]; int mark[8]; int dp[32][6][6][6][6][6][6]; void fun() { int i,j1,j2,j3,j4,j5,j6,flag,j,temp; memset(dp,0,sizeof(dp)); for(j1=0;j1<=4;j1++) for(j2=0;j2<=4;j2++) for(j3=0;j3<=4;j3++) for(j4=0;j4<=4;j4++) for(j5=0;j5<=4;j5++) for(j6=0;j6<=4;j6++) { if(j1+2*j2+3*j3+4*j4+5*j5+6*j6!=31)continue; dp[31][j1][j2][j3][j4][j5][j6]=1; } for(i=30;i>=0;i--) { for(j1=0;(j1<=4);j1++) for(j2=0;(j2<=4);j2++) for(j3=0;(j3<=4);j3++) for(j4=0;(j4<=4);j4++) for(j5=0;(j5<=4);j5++) for(j6=0;(j6<=4);j6++) { if(j1+2*j2+3*j3+4*j4+5*j5+6*j6!=i)continue; flag=1; for(j=1,temp=1+i;(temp<32)&&flag;temp++,++j) { switch(j) { case 1:if((j1+1<5)&&dp[temp][j1+1][j2][j3][j4][j5][j6])flag=0;break; // 在zoj上加上这个判断还WA,不加反而还能accept,真的有点让人不解! case 2:if((j1+2<5)&&dp[temp][j1][j2+1][j3][j4][j5][j6])flag=0;break; case 3:if((j1+3<5)&&dp[temp][j1][j2][j3+1][j4][j5][j6])flag=0;break; case 4:if((j1+4<5)&&dp[temp][j1][j2][j3][j4+1][j5][j6])flag=0;break; case 5:if((j1+5<5)&&dp[temp][j1][j2][j3][j4][j5+1][j6])flag=0;break; case 6:if((j1+6<5)&&dp[temp][j1][j2][j3][j4][j5][j6+1])flag=0;break; } } if(flag)dp[i][j1][j2][j3][j4][j5][j6]=1; } } } int main() { int i,len,sum; fun(); while(gets(s)!=NULL) { len=strlen(s); sum=0; memset(mark,0,sizeof(mark)); for(i=0;i<len;i++) { sum+=(s[i]-'0'); mark[(s[i]-'0')]++; if(sum>31) { break; } } printf("%s ",s); if(sum>31) { if(i%2==0) printf("B\n"); else printf("A\n"); continue; } if(dp[sum][mark[1]][mark[2]][mark[3]][mark[4]][mark[5]][mark[6]]) { if(i%2==0) printf("B\n"); else printf("A\n"); } else { if(i%2==0) printf("A\n"); else printf("B\n"); } } return 0; }
相关文章推荐
- ZOJ 1827 The Game of 31
- HDU 4155 The Game of 31
- hdu 4155 The Game of 31 博弈论
- ZOJ1827_The Game of 31
- HDU 4155 The Game of 31 (博弈)
- poj 4155 The Game of 31
- ZOJ1827 HDU4155 The Game of 31,博弈论+爆搜
- The Game of 31 (博弈)
- 【记忆化搜索】 HDU-4155-The Game of 31
- hdu 4155 The Game of 31
- HDOJ 4155 The Game of 31 博弈搜索
- hdu4155 The Game of 31
- zoj(2110)Tempter of the Bone(DFS+奇偶剪枝)
- ZOJ - 3880 Demacia of the Ancients (水)
- Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)
- poj--2242--The Circumference of the Circle&&[NYIST 1142&&ZOJ1090]
- 手机游戏软件开发的前景 The future of development of game software on mobiles
- ZOJ 2706 Thermal Death of the Universe(线段树区间更新)
- HDU 4839 The Game of Coins _(:зゝ∠)_
- ZOJ 2110 Tempter of the Bone