模拟---LCR
Description
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
Output
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
0
Sample Output
Source
#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的更多相关文章
- Gym 100646 Problem C: LCR 模拟题
Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...
- L008之前课程实战模拟。
L008之前课程实战模拟. . 安装CentOS 6.5 X86_64 . 配置网络 . 用CRT连接服务器 . 更换源http://mirrors.163.com/.help/CentOS6-Bas ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- Python 爬虫模拟登陆知乎
在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...
- HTML 事件(四) 模拟事件操作
本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4. ...
- 模拟AngularJS之依赖注入
一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...
- webapp应用--模拟电子书翻页效果
前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...
- javascript动画系列第一篇——模拟拖拽
× 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...
随机推荐
- SQL SERVER 安全性体系
主体和安全实体 在 SQL Server 2008中,“主体”就是可以访问受保护资源且能获得访问资源所需权限的任何个人.组或流程.与旧版 SQL Server 一样,可以在 Windows 中定义主体 ...
- 让Extjs EditorGridPanel 编辑时支持方向键
在用 extjs editorgridpanel 进行输入编辑的时候, 默认情况下只支持使用 tab 键可以实现焦点切换, 如果想让editorgridpanel 在编辑时通过方向键来实现焦点跳转切换 ...
- MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS[转]
MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS 简介 目前Mysql高可用的方案有好多,比如MMM,heartbeat+drbd,Cluster等,还有per ...
- Hybris电商方案介绍(企业全渠道) B2B B2C O2O建设
1). 什么是Hybris: hybris software成立于1997年,2013年与SAP整合,成为SAP旗下的一份子,提供全渠道客户互动与商务解决方案,该解决方案能够为各机构提供客户的实时背景 ...
- 自动化测试管理平台ATMS(V2.0.3_8.28)下载
自动化测试管理平台ATMS(V2.0.3_8.28)下载http://automationqa.com/forum.php?mod=viewthread&tid=2845
- IIS7 php wordpress 中文url 标签tag中文URL404解决方法
新建重写规则: <rule name="ChineseURL" stopProcessing="true"> <match url=" ...
- php ioc and web rest design
三个核心文件 1.公开访问web service配置 config.php 2.管理BEAN,扫描,注册,初始化等流程 ioc.php 3.管理 rest 拦载处理 ws.php config.php ...
- PLSQL快捷补充代码设置
菜单Tools-->Preferences...然后依次选择下图红色选项 弹出下图对话框 输入需要快速生成的语句点击保存 点击Save后在slq窗口中输入 设置的语句缩写 列入:第一个sf 然 ...
- iOS-开发技巧-页面布局
#pragma mark - Life Cycle//1.初始化//2.view did load//3.view will appear…#pragma mark - System Delegate ...
- 使用自带的JavaScriptSerializer序列化实体 指定的属性如何不序列化
public class GridConfig { public string width = "100%"; public string source = "dataA ...