Description LCR is a simple game for three or more players. Each player starts with three chips and the object is to be the last person to have any chips. Starting with Player 1, each person rolls a set of three dice. Each die has six faces, one face with an L, one with a C, one with an R and three with a dot. For each L rolled, the player must pass a chip to the player on their left (Player 2 is considered to be to the left of Player 1); for each R rolled, the player passes a chip to the player on their right; and for each C rolled, the player puts a chip in a central pile which belongs to no player. No action is taken for any dot that is rolled. Play continues until only one player has any chips left. In addition, the following rules apply: Input Input will consist of multiple test cases. Each test case will consist of one line containing an integer n (indicating the number of players in the game) and a string (specifying the dice rolls). There will be at most 10 players in any game, and the string will consist only of the characters `L', `C', `R' and `.'. In some test cases, there may be more dice rolls than are needed (i.e., some player wins the game before you use all the dice rolls). If there are not enough dice rolls left to complete a turn (for example, only two dice rolls are left for a player with 3 or more chips) then those dice rolls should be ignored. A value of n = 0 will indicate end of input. Output For each test case, output the phrase `Game i :' on a single line (where i is the case number starting at 1) followed by a description of the state of the game. This desciption will consist of n + 1 lines of the form Sample Input
Sample Output
|
纯模拟题,水题。但是要认真读题,逻辑上要认真考虑,争取一次AC。
#include<queue> #include<cstring> #include<cstdio> using namespace std; int sum[14]; char s[1000000]; int main() { int n,kase=1; while(scanf("%d",&n)!=EOF&&n) { if(kase!=1) puts(""); for(int i=0;i<n;i++) sum[i] = 3; scanf("%s",s); int len = strlen(s); int i=0,now=0,left=n,C=0; while(i<len) { if(now==n) now=0; if(sum[now]==0) { now++; continue; } int j=0,dice = sum[now]; if(sum[now]>3) dice = 3; if(i+dice>len) { break; } for(j=0;j<dice&&i+j<len;j++) { if(s[i+j]=='.') continue; else if(s[i+j]=='L') { int Next = now+1; if(Next==n) Next=0; if(sum[Next]==0) left++; sum[Next]++; sum[now]--; if(sum[now]==0) left--; } else if(s[i+j]=='R') { int Next = now-1; if(Next==-1) Next=n-1; if(sum[Next]==0) left++; sum[Next]++; sum[now]--; if(sum[now]==0) left--; } else if(s[i+j]=='C') { C++; sum[now]--; if(sum[now]==0) left--; } //if(left==1) break; } i=i+j; now++; if(left==1) break; } if(now==n) now = 0; while(sum[now]==0) { now++; if(now==n) now = 0; } printf("Game %d: ",kase++); for(int i=0;i<n;i++){ if(i==now&&left==1) printf("Player %d:%d(W) ",i+1,sum[i]); else if(i==now) printf("Player %d:%d(*) ",i+1,sum[i]); else printf("Player %d:%d ",i+1,sum[i]); } printf("Center:%d ",C); } }