Gym 100646 Problem C: LCR 模拟题

时间:2022-09-30 11:47:36

Problem C: LCR

题目连接:

http://codeforces.com/gym/100646/attachments

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:

  1. A player with no chips is 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 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 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

Player 1:c1

Player 2:c2

...

Player n:cn

Center:ct

where c1, c2 ... cn are the number of chips each player has at the time the simulation ended (either

because some player has won or there are no more remaining dice rolls) and ct is the number of chips

in the center pile. In addition, if some player has won, you should append the string “(W)” after their

chip count; otherwise you should append the string “(*)” after the chip count of the player who is the

next to roll. The only blank on any line should come before the game number or the player number.

Use a single blank line to separate test cases.

Sample Input

3 LR.CCR.L.RLLLCLR.LL..R...CLR.

5 RL....C.L 0

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

Center:1

Hint

题意

模拟题,每个人一开始有三个薯片,然后从1开始,扔最多三个骰子,如果这个人的骰子小于3个的话,就扔他拥有的个数个骰子,如果他没有骰子的话,直接递给下个人。

如果扔到L,那么就把薯片给左边,扔到R就给右边,扔到C就扔中间,扔到点,什么都不做。

如果最后的骰子数小于这个人需要扔的,那就直接无视掉。

胜利条件是一个人拥有所有人最后的薯片。

如果游戏能结束,就直接输出胜利玩家,否则就输出下一个该谁扔。

题解:

模拟题,就模拟就好了。

代码

#include<bits/stdc++.h>
using namespace std; int n;
string s;
int cnt[100];
int cas,mi,now,t;
void init(){
memset(cnt,0,sizeof(cnt));
t=0;
mi=0;
now=0;
}
void soe(int x,int y,int z){
for(int i=x;i<y;i++){
if(s[i]=='R'){
cnt[z]--;
cnt[(z+n-1)%n]++;
}
if(s[i]=='L'){
cnt[z]--;
cnt[(z+1)%n]++;
}
if(s[i]=='C'){
cnt[z]--;
mi++;
}
if(s[i]=='.')continue;
}
}
void solve(){
init();
mi=0;
printf("Game %d:\n",++cas);
memset(cnt,0,sizeof(cnt));
cin>>s;
for(int i=0;i<n;i++)cnt[i]=3;
int cccc=0;
int flag = -1;
while(t<s.size()){
cccc++;
if(cccc>1000000)break;
if(t+min(cnt[now],3)<=s.size()){
int pre = cnt[now];
soe(t,t+min(cnt[now],3),now);
t+=min(pre,3);
now++;
now%=n;
while(cnt[now]==0){
now++;
now%=n;
}
}else{
break;
} for(int i=0;i<n;i++){
if(cnt[i]+mi==3*n)flag=i;
} if(flag!=-1)break;
} for(int i=0;i<n;i++){
printf("Player %d:%d",i+1,cnt[i]);
if(flag==i)printf("(W)");
if(flag==-1&&i==now)printf("(*)");
printf("\n");
} printf("Center:%d\n",mi);
printf("\n");
}
int main(){
//freopen("1.in","r",stdin);
while(scanf("%d",&n)!=EOF){
if(n==0)break;
solve();
}
}

Gym 100646 Problem C: LCR 模拟题的更多相关文章

  1. Gym 100646 Problem E&colon; Su-Su-Sudoku 水题

    Problem E: Su-Su-Sudoku/center> 题目连接: http://codeforces.com/gym/100646/attachments Description By ...

  2. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  3. 2010-2011 ACM-ICPC&comma; NEERC&comma; Moscow Subregional Contest Problem F&period; Finance 模拟题

    Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...

  4. 2010-2011 ACM-ICPC&comma; NEERC&comma; Moscow Subregional Contest Problem I&period; Interest Targeting 模拟题

    Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...

  5. Western Subregional of NEERC&comma; Minsk&comma; Wednesday&comma; November 4&comma; 2015 Problem K&period; UTF-8 Decoder 模拟题

    Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...

  6. codeforce gym&sol;100495&sol;problem&sol;K—Wolf and sheep 两圆求相交面积 与 gym&sol;100495&sol;problem&sol;E—Simple sequence思路简述

    之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...

  7. sdut 2162&colon;The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  8. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  9. cdoj 25 点球大战&lpar;penalty&rpar; 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. ORACLE设置id自增长

    1.创建序列create sequence sequence_userinfo start with 1 increment by 1 minvalue 1 maxvalue 999999 nocyc ...

  2. iOS中的谓词(NSPredicate)使用

    http://www.cocoachina.com/ios/20160111/14926.html 首先,我们需要知道何谓谓词,让我们看看官方的解释: The NSPredicate class is ...

  3. LeanCloud获取最近会话列表和获取最后一条聊天记录

    最近公司有项目需要集成IM聊天功能,领导要求用LeanCloud集成,搞不出来就要背包滚蛋啊,没办法只能硬着头皮搞了. 刚拿到官方提供的demo感觉:嗯,不错.图片语音啥的都有了,但尼玛这还不够啊,还 ...

  4. &lpar;一&rpar;Java工程化--Maven基础

    Maven 读作['mevən] 翻译成中文是"内行,专家" Maven是什么 包依赖的前世今生: 原始的jar包引用--> ant --> maven. 是一种项目管 ...

  5. windows和linux环境下keras的模型框架可视化

    1.简介 keras提供了模型可视化模块,下面讲解下安装教程和简易教程. 2.安装教程 2.1windows环境下的安装 2.1.1安装指定模块 pip install pydot-ng pip in ...

  6. virtualbox中 Ubuntu安装增强功能

    1. 执行,等待,当提示按 Enter 时按下 2. 在文件管理中找到挂载的文件,切换到该目录,执行命令 sudo ./VBoxLinuxAdditions.run 3. 重启

  7. VDB R&amp&semi;D

    VDB Data value visualize: 结论从houdini得知. API常用文字: interior:内部 Narrow-band:窄带 background:窄带外 SDF: XY p ...

  8. zsh&plus;on-my-zsh配置教程指南(程序员必备)

    本文以CentOS 7/Mac 为例,介绍zsh的配置使用教程. 准备 查看当前环境shell echo $SHELL <!-- more --> 查看系统自带哪些shell cat /e ...

  9. Leetcode 868&period; 二进制间距

    868. 二进制间距  显示英文描述 我的提交返回竞赛   用户通过次数201 用户尝试次数220 通过次数207 提交次数396 题目难度Easy 给定一个正整数 N,找到并返回 N 的二进制表示中 ...

  10. Linux读书笔记第三、四章

    第三章 主要内容: 进程和线程 进程的生命周期 进程的创建 进程的终止 1. 进程和线程 进程和线程是程序运行时状态,是动态变化的,进程和线程的管理操作(比如,创建,销毁等)都是有内核来实现的. Li ...