传送门

问题描述:

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 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.

输出说明:

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

SAMPLEOUTPUT:

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

思路:

理解上比较复杂的一道题目,题意大概是一群人(人数大于等于3)玩掷骰子的游戏,每人一开始有3个筹码,每次骰3个骰子,如果是L就把一个骰子给左边的人,如果是R就把一个骰子给右边的人,如果是C就把一个骰子放在中心(这个歌骰子不属于任何人),如果是’.'就什么也不进行操作,如果手中的筹码数量小于3,就骰对应数量的骰子(例如手中有1个筹码就骰一个骰子),如果手中没有筹码,就不骰出骰子(注意,没有筹码不意味退出游戏,还在游戏中,因为他左右的人有可能给他筹码)游戏结束的情况是当只有一个人手中有筹码,其他所有人的筹码数都为0,或者输入的一行骰子的情况都用完了。(如果剩余骰子情况数量,小于应骰的数量,直接忽略这些操作,直接结束游戏)输出则要主要格式,以及标注赢家(最后进行操作的玩家)写起来很烦,理解了很简单,加油。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int num[100];
int no,middle,now,t,flag,i,cccc,pre,len;
void pass(int x,int y,int z)
{for(int i=x;i<y;i++){if(s[i]=='R'){num[z]--;num[(z+n-1)%n]++;}if(s[i]=='L'){num[z]--;num[(z+1)%n]++;}if(s[i]=='C'){num[z]--;middle++;}if(s[i]=='.') /**/continue;}
}
int main()
{cin>>n;while(n){memset(num,0,sizeof(num));t=0;middle=0;now=0;cout<<"Game "<<++no<<":"<<endl;memset(num,0,sizeof(num));cin>>s;len=s.length();for(i=0;i<n;i++){num[i]=3;}flag = -1;while(t<len){if(t+min(num[now],3)<=s.size()){pre=num[now];pass(t,t+min(num[now],3),now);t+=min(pre,3);now++;now%=n;while(num[now]==0){now++;now%=n;}}else{break;}for(int i=0;i<n;i++){if(num[i]+middle==3*n){flag=i;}}if(flag!=-1) break;}for(i=0;i<n;i++){cout<<"Player "<<i+1<<":"<<num[i];if(flag==i){cout<<"(W)";}if(flag==-1&&i==now){cout<<"(*)";}cout<<endl;}cout<<"Center:"<<middle<<endl;cin>>n;if (n!=0){cout<<endl;}}return 0;
}

HDU-2778 LCR相关推荐

  1. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  2. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  3. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  4. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  5. hdu 1312 Red and Black 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...

  6. HDU 1429 胜利大逃亡(续) (BFS+位压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  7. hdu 1272 小希的迷宫

    Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该 ...

  8. HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1157 题目描述: ...

  9. 大数加法【HDU 1002】

    大数加法模板 一般的加法只要int类型的两数直接相加即可,大一点的数可以设为long long类型,而超过长整型的数则属于大数问题了,大数加法其实也比较简单,利用数组实现就可以啦: 主要思想如下: ( ...

  10. hdu 2665(主席树查询区间k大值)

    先贴我自己写的代码做模板虽然跟原博主没什么两样.(一开始空间开的4*maxn,交到hdu上一直TLE很奇怪) #include<bits/stdc++.h> using namespace ...

最新文章

  1. 求数的绝对值一定是正数_「口袋数学」绝对值的几何意义探究及应用,培优课程...
  2. 【mycat】简介及安装
  3. python 解码json数据并在一个OrderdDict中保留其顺序
  4. 扫雷游戏网页版_做游戏,单人行动可行吗(3.让我试试扫雷)
  5. CentOS 6.6 安装 Node.js
  6. 数据结构与算法C语言版—— 数据结构的详细介绍
  7. error LNK2005 原理及解决办法
  8. Serializer对象
  9. hack the box(5985 WinRM)
  10. win10 安装 hadoop 3.3.1报错 Unable to load native-hadoop library
  11. 【PTA】日程安排(多重继承+重载)
  12. Neo4j学习笔记-Embedded嵌入模式简单示例
  13. 《调和级数》python
  14. 串口DCB定义,配置例程
  15. ajax实现微博点赞功能
  16. 对学姐的U-net网络的学习杂记
  17. Math 的 ceil、floor、round方法详解及示例
  18. 数据模型工具--powerDesigner下载分享
  19. 如何获得免费虚拟主机,云服务器呢?(免费)
  20. sql创建查询视图语句

热门文章

  1. python期末考试及答案广东_Python2020期末考试试题及答案
  2. springboot之ActiveMQ连接池
  3. Elsevier期刊返修提交latex source files_Latex高亮文本时页码被影响问题
  4. RocketMQ的Rebalance机制
  5. 1g内存服务器Apache怎么优化,Apache性能优化-解决吃内存的问题 | kTWO-个人博客
  6. 【强化学习论文合集】二十二.2020国际机器学习大会论文(ICML2020)
  7. 达摩院开源低成本大规模分类框架FFC CVPR论文深入解读
  8. 10采用区块链智能合约管理智能城市房地产交易的概念框架
  9. 职业程序员必看之文章
  10. 码农学技术————六个月学习python全栈【Day01】