Gym 100646 Problem C: LCR 模拟题
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:
- A player with no chips is not out of the game, since they may later gain chips based on other
players’ rolls. - 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 模拟题的更多相关文章
- Gym 100646 Problem E: Su-Su-Sudoku 水题
Problem E: Su-Su-Sudoku/center> 题目连接: http://codeforces.com/gym/100646/attachments Description By ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题
Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题
Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题
Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...
- codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述
之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
随机推荐
- 读asyncio模块源码时的知识补漏
硬着头皮看了一周的asyncio模块代码,了解了大概的执行流程,引用太多,成尤其是对象间函数的引用. 光是这么一段简单的代码: # coding: utf8 import asyncio import ...
- J2EE规范 - 13种规范
J2EE是由SUN提出的用于简化开发企业级应用程序的一系列规范的组合,J2EE基于中间层集成的框架的方式为应用开发提供了一个统一的开发平台.基于容器管理.组件化的模型为企业建立一个高可用性,高可靠性可 ...
- MySQL索引背后的数据结构及算法原理 (转)
摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BT ...
- Chrome插件笔记之content_scripts
一.概论 说这个之前先看一个段子,讲的是甲方有一奇葩客户,这客户看一网站某些样式很别扭不得劲,非要让乙方修改,乍一听没毛病,但关键是这网站不是乙方家的,根本没有修改权限,怎么办,客户就是上帝,上帝的要 ...
- 使用 scm-manager 搭建 git/svn 代码管理仓库(一)
1.在官网上下载scm-manager 下载地址 https://www.scm-manager.org/download/ 选择下载文件 2. 配置java 环境 参照文章:https://jin ...
- mysqlbinlog 查看mysql bin 日志 mysqlbinlog: unknown variable 'default-character-set=utf8'
mysqlbinlog mysql-bin.000036 | less 查询包含几个字段的语句: mysqlbinlog mysql-bin.000036| egrep '(201103061000 ...
- C# 百度搜索结果xpath分析
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- win10 安装IIS说明操作
1.点左下角的Windows,所有应用,找到Windows系统,打开控制面板. 2.进入控制面板之后点击程序,可能你的控制面板和图片里的不太一样,不过没关系,找到程序两个字点进去就行. 3.接下来,在 ...
- Python学习四|变量、对象、引用的介绍
变量 变量创建:一个变量也就是变量名,就像a,当代码第一次赋值时就创建了它.之后的赋值将会改变已创建的变量名的值,从技术上讲,Python在代码运行之前先检测变量名,可以当成是最初的赋值创建了变量. ...
- Android BLE设备蓝牙通信框架BluetoothKit
BluetoothKit是一款功能强大的Android蓝牙通信框架,支持低功耗蓝牙设备的连接通信.蓝牙广播扫描及Beacon解析. 关于该项目的详细文档请关注:https://github.com/d ...