The simulation questions are all water problems. But to seriously read the problem, logic to seriously consider, to win an AC.
| Description LCR is a simple game for three or more players. Each player starts with three chips and the object are to was the last person to has any chips. Starting with Player 1, each person rolls a set of three dice. Each of the die have six faces, one face with an L, one with a C, one with a R and three with a dot. For each L rolled, the player must pass a chip to the player in their left (player 2 is considered Ayer 1); For each R rolled, the player passes a chip to the player in 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 a chips left. In addition, the following rules apply: 1. A player with no chips are not out of the game, since they may later gain chips based on other players ' rolls. 2. A player with only 1 or 2 chips left only rolls 1 or 2 dice, respectively. A player with no chips left does is not roll but just passes the dice to the next player. Your job is to simulate this game given a sequence of dice rolls. Input Input would consist of multiple test cases. Each test case would consist of one line containing an integer n (indicating the number of players in the game) and a Strin G (Specifying the dice rolls). There'll is at the Max players in any game, and the string would consist only of the characters ' L ', ' C ', ' R ' and '. In some test cases, there is more dice rolls than is needed (i.e., some player wins the game before you use all the D Ice rolls). If There is not enough dice rolls left to complete a turn (for example, only the dice rolls is left for a player with 3 or more chips) then those dice rolls should be ignored. A value of n = 0 would indicate end of input. Output For each test case, the output the phrase ' Game I: ' On a single line (where I am the case number starting at 1) followed by a Description of the state of the game. This desciption would consist of n + 1 lines of the form Player 1:C1 Player 2:C2 ... Player N:CN Center:ct where C1, c2...cn is the number of chips each player have at the time the simulation ended (either because some player have Won or there is no more remaining dice rolls) and CT is the number of chips in the center pile. In addition, if some player have won, you should append the string ' (W) ' after their chip count; Otherwise you should append the string ' (*) ' after the chip count of the ' the ' the ' the ' and ' next to roll '. The only blank on any line should come before the game number or the player number. Use of a single blank line to separate test cases. Sample Input
Sample Output Game 1:player 1:0 player 2:0 player 3:6 (W) center:3 Game 2:player 1:1 player 2:4 player 3:1 player 4:4 (*) Player 5:4 Cen Ter:1
|
#include <queue>#include<cstring>#include<cstdio>using namespacestd;intsum[ -];Chars[1000000];intMain () {intN,kase=1; while(SCANF ("%d", &n)!=eof&&N) {if(kase!=1) puts (""); for(intI=0; i<n;i++) Sum[i] =3; scanf ("%s", s); intLen =strlen (s); intI=0, now=0, left=n,c=0; while(i<Len) { if(now==n) now=0; if(sum[now]==0) { now++; Continue; } intj=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') { intNext = 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') { intNext = 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:\n", kase++); for(intI=0; i<n;i++){ if(i==now&&left==1) printf ("Player%d:%d (W) \ n", i+1, Sum[i]); Else if(I==now) printf ("Player%d:%d (*) \ n", i+1, Sum[i]); Elseprintf"Player%d:%d\n", i+1, Sum[i]); } printf ("center:%d\n", C); }}
HDU 2778 LCR Simulation problem