HDU  2778

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
 

Source

2008 East Central Regional Contest
 
题意:有n(小于等于10)个人,每个人3个筹码,编号为n,n-1,n-2,……,3,2,1  有3个筛子,六个面分别为L、R、C和三个点(.) ,从1这个人开始掷3个筛子,若为L,表示给左边人一个筹码,R为给右边一个筹码,C表示放一个筹码在中间,点表示不进行操作。若这个人筹码少于3个,则掷相应筹码数的筛子,例如这个人没有筹码了,他就不掷筛子,直接给下一个人。给一个筛子序列,模拟过程,序列长度可能在分出输赢时还有剩余,也可能还没分出输赢,长度不够。若过程中剩余筛子数不够这个人掷(小于这个人的筹码数),则剩余筛子忽略不计。
 
思路:本题就是模拟,没有什么算法,有两点需要注意的地方(我开始时没有注意到这两点,代码wa了很多次,终于找出它bug了!) 
1、注意这样的数据   2 CC.RRC   第二个人掷完后没有筛子序列了,但是1号已经赢了。
2、筛子序列遍历完了但是还没有胜负,i号掷完后不一定改i+1掷,因为i+1可能没有筹码了,所以(*)不一定在i+1号后。
 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
char str[];
int flag,tp,center;
int p[]; bool check(int n)
{
for(int k=;k<=n;k++)
{
if(p[k]+center==*n)
{
tp=k;
flag=;
return true;
}
}
return false;
} void moli(int n)
{
int len=strlen(str);
for(int i=;i<len;)
{
if(check(n)) return ;
int t;
if(p[tp]>=) t=;
else t=p[tp];
if(len-i<t)
{
return;
}
for(int j=;j<t;j++)
{
if(str[i]=='L')
{
p[tp]--;
if(tp==n) p[]++;
else p[tp+]++;
}
else if(str[i]=='R')
{
p[tp]--;
if(tp==) p[n]++;
else p[tp-]++;
}
else if(str[i]=='C')
{
p[tp]--;
center++;
}
i++;
}
if(check(n)) return ;
tp++;
if(tp==n+) tp=;
}
while(!p[tp])
{
if(tp==n) tp=;
else tp++;
}
} int main()
{
int n,Case=;
while(scanf("%d",&n)!=EOF&&n)
{
scanf("%s",str);
flag=;
tp=;
center=;
for(int i=;i<;i++)
p[i]=;
moli(n);
if(Case>) printf("\n");
printf("Game %d:\n",Case++);
for(int i=;i<=n;i++)
{
printf("Player %d:%d",i,p[i]);
if(tp==i&&flag) printf("(W)\n");
else if(tp==i&&!flag) printf("(*)\n");
else
printf("\n");
}
printf("Center:%d\n",center);
}
return ;
}

模拟---LCR的更多相关文章

  1. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

  2. L008之前课程实战模拟。

    L008之前课程实战模拟. . 安装CentOS 6.5 X86_64 . 配置网络 . 用CRT连接服务器 . 更换源http://mirrors.163.com/.help/CentOS6-Bas ...

  3. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  4. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  5. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  6. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  7. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  8. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

  9. javascript动画系列第一篇——模拟拖拽

    × 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...

随机推荐

  1. neo4j安装与示例

    Neo4j有两种访问模式:服务器模式和嵌入模式参考,下面主要讲windows下这两种模式的配置与访问示例 1 Windows下Neo4j服务器模式安装与示例 安装: 1.下载Neo4j,我下载的版本是 ...

  2. Multipart/form-data POST文件上传详解

    Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form ...

  3. 泊松回归(Poisson Regression)

    本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ Linear Regression预测的目标\(Y\)是连续值, Logistic Regre ...

  4. Top100Summit全球案例研究峰会第一天总结——云计算和大数据

    很荣幸受邀参加Top100Summit全球软件案例研究峰会,这次的大会主题是<技术推动商业变革>,组委会从全国投稿的460多件案例中甄选出100件具有代表价值的案例,进行为期4天的分享,第 ...

  5. 学习Sass之安装Sass(一)

    为什么使用Sass 作为前端(html.javascript.css)的三大马车之一的css,一直以静态语言存在,HTML5火遍大江南北了.javascript由于NODE.JS而成为目前前后端统一开 ...

  6. 10个TWaver 网页3D可视化精彩案例

    以下网页3D案例均为TWaver原创出品,推荐使用Chrome, FireFox, Safari等对WebGL支持良好的浏览器运行.案例排名不分先后,如需Demo,可直接申请试用.   1. 化学元素 ...

  7. Ajax请求WebService跨域问题 [转载]

    1.背景 用Jquery中Ajax方式在asp.net开发环境中WebService接口的调用 2.出现的问题 原因分析:浏览器同源策略的影响(即JavaScript或Cookie只能访问同域下的内容 ...

  8. 【转】Oracle RAC 环境下的连接管理

    文章转自:http://www.oracle.com/technetwork/cn/articles/database-performance/oracle-rac-connection-mgmt-1 ...

  9. 又是一个小正则replace

    var a = "http://www.xx.com?id=111&-deb"; var b = "http://www.xx.com?-deb&id=1 ...

  10. Inkpad绘图原理浅析

    本文新版本已转移到开源中国,欢迎前往指导. Inkpad是一款非常优秀的iPad矢量绘图软件,保管你一看见就忘不了.我的感觉是“一览众山小”.“相见甚晚”,以至于我写的TouchVG就是“小巫见大巫” ...