hdu4155 The Game of 31
2013-10-02 23:04
316 查看
The Game of 31
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 480 Accepted Submission(s): 234
[align=left]Problem Description[/align]
The game of 31 was a favourite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labelled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately
withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming
each player plays the remainder of the game using a perfect strategy.
For example, in the following game player B wins:
Player A plays 3
Player B plays 5
Player A plays 6
Player B plays 6
Player A plays 5
Player B plays 6
[align=left]Input[/align]
The input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete
the game using a perfect strategy for both players and to determine who wins.
[align=left]Output[/align]
For each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game.
[align=left]Sample Input[/align]
356656
35665
3566
111126666
552525
[align=left]Sample Output[/align]
356656 B
35665 B
3566 A
111126666 A
552525 A壮态很少,暴搜!
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) int a[7];char str[300]; int dfs(int x){ int i; if(x>31)return 1; for(i=1;i<=6;i++){ if(a[i]<4){ a[i]++; if(dfs(x+i)==0){ a[i]--; return 1; } a[i]--; } } return 0; } int main() { int i,ans; while(scanf("%s",str)!=EOF){ printf("%s ",str); mem(a,0); for(i=0,ans=0;str[i]!='\0';i++){ ans+=str[i]-'0'; a[str[i]-'0']++; if(ans>31)break; } if(ans>31){ if(i&1)printf("A\n"); else printf("B\n"); } else { int re=dfs(ans); if((i&1)) re=re?0:1; if(re)printf("A\n"); else printf("B\n"); } } return 0; }
相关文章推荐
- ZOJ1827 HDU4155 The Game of 31,博弈论+爆搜
- hdu 4155 The Game of 31 博弈论
- The Game of 31 (博弈)
- HDU 4155 The Game of 31 (博弈)
- HDOJ 4155 The Game of 31 博弈搜索
- HDU 4155 The Game of 31
- ZOJ 1827 The Game of 31
- zoj 1827 The Game of 31
- ZOJ1827_The Game of 31
- hdu 4155 The Game of 31
- 【记忆化搜索】 HDU-4155-The Game of 31
- poj 4155 The Game of 31
- The Game of iGameGuardian7.3.1
- Codeforces 839B-Game of the Rows
- The game of Fort/Da是自虐还是自保?
- The Structure of Action Game AI
- The Game API package provides a series of classes that enable the development of rich gaming content for wireless devices.
- Mastering the game of Go with deep neural networks and tree search
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows