模拟---LCR

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[1000005];
int flag,tp,center;
int p[15];

bool check(int n)
{
    for(int k=1;k<=n;k++)
    {
        if(p[k]+center==3*n)
        {
            tp=k;
            flag=1;
            return true;
        }
    }
    return false;
}

void moli(int n)
{
    int len=strlen(str);
    for(int i=0;i<len;)
    {
        if(check(n)) return ;
        int t;
        if(p[tp]>=3) t=3;
        else         t=p[tp];
        if(len-i<t)
        {
            return;
        }
        for(int j=0;j<t;j++)
        {
            if(str[i]==‘L‘)
            {
                p[tp]--;
                if(tp==n) p[1]++;
                else      p[tp+1]++;
            }
            else if(str[i]==‘R‘)
            {
                p[tp]--;
                if(tp==1) p[n]++;
                else      p[tp-1]++;
            }
            else if(str[i]==‘C‘)
            {
                p[tp]--;
                center++;
            }
            i++;
        }
        if(check(n)) return ;
        tp++;
        if(tp==n+1) tp=1;
    }
    while(!p[tp])
    {
        if(tp==n) tp=1;
        else tp++;
    }
}

int main()
{
    int n,Case=1;
    while(scanf("%d",&n)!=EOF&&n)
    {
        scanf("%s",str);
        flag=0;
        tp=1;
        center=0;
        for(int i=0;i<15;i++)
        p[i]=3;
        moli(n);
        if(Case>1) printf("\n");
        printf("Game %d:\n",Case++);
        for(int i=1;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 0;
}
时间: 2024-09-30 14:10:42

模拟---LCR的相关文章

hdu 2778 LCR 模拟题

模拟题都是水题.但是要认真读题,逻辑上要认真考虑,争取一次AC. 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.

L008之前课程实战模拟。

L008之前课程实战模拟. 1. 安装CentOS 6.5 X86_64 2. 配置网络 3. 用CRT连接服务器 4. 更换源http://mirrors.163.com/.help/CentOS6-Base-163.repo 5. 对比老源和新源 6. 安装必要的软件:tree telnet dos2unix syssstat lrzsz 7. 关闭防火墙 8. 关闭selinux防火墙 9. 查询3模式下都有什么开机启动项,只保留crond network sshd rsyslog服务 1

CentOS系统启动及内核大破坏模拟实验

讲过了centos的启动流程,此时是不是想来点破坏呢?那就尽情的玩耍吧,记得在实验之前拍个快照,万一哪个环节错误恢复不回来了呢,毕竟数据无价,话不多说,开始. 一.删除伪系统根.(ramdisk文件) (1)模拟误操作删除ramdisk文件. ①模拟误删除initramfs-3.10.0-514.el7.x86_64.img文件. ②为当前正在使用的内核重新制作ramdisk文件 格式为:mkinitrd /boot/initramfs-$(uname -r).img $(uname -r) (

NYOJ 2356: 哈希计划【模拟】

题目描述 众所周知,LLM的算法之所以菜,就是因为成天打游戏,最近LLM突然想玩<金庸群侠传X>,结果进去后各种被虐,LLM就开始研究这个游戏的代码,顺便还学会了一点点点点lua语言,然后就开始了伟大的改游戏代码之旅,然后LLM发现自己too young了,这个游戏把所有的文本都进行了哈希,如果自己改了代码或者剧情文本的话它哈希出来的值就会和原来的哈希值不一样......然后游戏就会打不开.....,现在LLM发现了文本的哈希函数,要求你写个程序,功能为: 输入一段字符串,输出一个哈希值 为了

爬虫——模拟点击动态页面

动态页面的模拟点击: 以斗鱼直播为例:http://www.douyu.com/directory/all 爬取每页的房间名.直播类型.主播名称.在线人数等数据,然后模拟点击下一页,继续爬取 #!/usr/bin/python3 # -*- conding:utf-8 -*- __author__ = 'mayi' """ 动态页面的模拟点击: 模拟点击斗鱼直播:http://www.douyu.com/directory/all 爬取每页房间名.直播类型.主播名称.在线人数

爬虫——网站模拟登录

使用Selenium与PhantomJS模拟登录豆瓣:https://www.douban.com/ #!/usr/bin/python3 # -*- conding:utf-8 -*- __author__ = 'mayi' """ 模拟登录豆瓣:https://www.douban.com/ """ from selenium import webdriver # 调用环境变量指定的PhantomJS浏览器创建浏览器对象,executable

python爬虫 模拟登陆校园网-初级

最近跟同学学习爬虫的时候看到网上有个帖子,好像是山大校园网不稳定,用py做了个模拟登陆很有趣,于是我走上了一条不归路..... 先上一张校园网截图 首先弄清一下模拟登陆的原理: 1:服务器判定浏览器登录使用浏览器标识,需要模拟登陆 2: 需要post账号,密码,以及学校id python走起,我用的2.7版本,用notepad++写的,绑定python可以直接运行 由于是模拟网页登陆,需要导入urllib urllib2 cookielib库,前两个有与网页直接的接口,cookielib就是用来

Android模拟位置信息

Android模拟位置程序,俗称GPS欺骗,只能修改采用GPS定位的软件. 手机定位方式目前有4种:基站定位,WIFI定位,GPS定位,AGPS定位 常见的修改手法: 1. 抓包欺骗法,抓包改包欺骗服务器端, 但是得专门去针对某款app,而且现在很多app数据包都加密了 2. hook java层经纬度获取函数, 这个方法以前可以用,现在不行了 3. hook native层经纬度获取函数 4. 使用允许模拟地址位置信息(不是很通用有版本限制) 为了修改微信朋友圈地理位置信息,为了好玩 试过了上

CSU 1112: 机器人的指令【模拟题】

1112: 机器人的指令 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1858  Solved: 682 [Submit][Status][Web Board] Description 数轴原点有一个机器人.该机器人将执行一系列指令,你的任务是预测所有指令执行完毕之后它的位置. ·LEFT:往左移动一个单位 ·RIGHT: 往右移动一个单位 ·SAME AS i: 和第i 条执行相同的动作.输入保证i 是一个正整数,且不超过之前执行指令数 In