MUSICAL CHAIRS
时间限制: 1 Sec 内存限制: 128 MB
提交: 386 解决: 76
[提交] [状态] [命题人:admin]
题目描述
Musical chairs is a game frequently played at children’s parties. Players are seated in a circle facing outwards. When the music starts, the players have to stand up and move clockwise round the chairs. One chair is removed, and when the music stops the players all have to try to sit down on one of the chairs. The player who does not manage to sit down is out, and the game continues until there is just one player left, who is the winner.

输入
The first line contains a single integer, N which is the number of players (1 < N <= 15).
The next N lines have the names of the players.
The next line contains R, an integer which tells how many rounds are to be processed (0 < R < N). The next R lines each contain a pair of integers S and M, separated by a space. S is the number of the seat to be removed. Seats are numbered from 1 to the number of seats remaining in a clockwise direction.
M is the number of moves made before the music stops (0 < M <= 30). A move takes a player from one seat to the next in a clockwise direction. A move from the highest seat number takes a player to seat 1.

输出
After each round has taken place, output a line
has been eliminated.
where is the name of the person who does not find a seat. This will be the person who would have ended up at the seat which was removed.
At the end of the specified number of moves, output a line which either says
has won.
where a single player remains, or
Players left are .
where the game is not yet finished.
contains the name of each player not yet eliminated in the same order as in the input. The names are separated by spaces.

样例输入
复制样例数据
5
Anne
Bill
Chen
Di
Everet
4
3 6
2 8
1 5
2 6
样例输出
Bill has been eliminated.
Anne has been eliminated.
Chen has been eliminated.
Everet has been eliminated.
Di has won.

题目大意:
先输入一个数字nnn,代表有nnn个人参加游戏,其下nnn行输入每个参与者的名字,从111到nnn依次编号,然后这nnn个人围绕nnn个凳子旋转,每回合将抽掉一个凳子,而这代表着将有一个人被淘汰,在每回合中,所有人绕着凳子顺时针旋转,且每回合都将凳子重新从111开始编号。其后先输入一个数字ttt,代表游戏进行了ttt个回合,对于每回合,输入两个整数rrr和mmm,代表此回合抽掉的凳子编号以及玩家旋转的次数。输出每回合淘汰掉的人,按照最后剩下的人的个数输出不同的格式。

解题思路:
此题知道意思后直接模拟即可,我认为用双端队列比较好模拟。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
string str[20];
deque<int> q;
int arr[100];
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);//ios::sync_with_stdio(0),cin.tie(0);int n;cin>>n;string s;rep(i,1,n) {cin>>s;str[i]=s;}lep(i,n,1)q.push_back(i);int t;cin>>t;int r,m;while(t--) {cin>>r>>m;while(m--) {int t=q.front();q.pop_front();q.push_back(t);}rep(k,1,r-1) {int t=q.back();q.pop_back();q.push_front(t);}int num=q.back();q.pop_back();rep(k,1,r-1) {int t=q.front();q.pop_front();q.push_back(t);}cout<<str[num]<<" has been eliminated."<<endl;}int cnt=0;while(!q.empty()) {arr[++cnt]=q.front();q.pop_front();}sort(arr+1,arr+1+cnt);if(cnt>1) {cout<<"Players left are";rep(i,1,cnt) {cout<<" "<<str[arr[i]];}cout<<"."<<endl;}if(cnt==1) {cout<<str[arr[1]]<<" has won."<<endl;}return 0;
}

MUSICAL CHAIRS【模拟】相关推荐

  1. MUSICAL CHAIRS (模拟)

    题目描述 Musical chairs is a game frequently played at children's parties.  Players are seated in a circ ...

  2. 编程论语 EPIGRAMS IN PROGRAMMING

    作者: Alan J. Perlis艾伦·佩利,1966年图灵奖 One man's constant is another man's variable. 一个人的常量是另一个人的变量. Funct ...

  3. 2019 East Central North America 部分题解

    题目链接:点这里 A.Retribution! 题意 给出nnn个人的位置.mmm个仓库1的位置以及ppp个仓库2的位置.给每个人分配一个仓库111和仓库222,问这所有的最小距离总和. 解题思路 这 ...

  4. MIT CMS.300 Session 5 – UNWRITTEN RULES 游戏的潜在规则

    前言: 这一讲聚焦游戏学研究的社会学方面.潜在规则是基于人类社会文化的规则,是人与人之间的默契和道德.潜在规则并不是游戏特有的,而是社会规则对于游戏世界的入侵.游戏世界虽然是独立的,但却没有完全的独立 ...

  5. TED | 25岁前,请逼自己成为这样的人

    When I was in my 20s, I saw my very first psychotherapy client. I was a Ph.D. student in clinical ps ...

  6. 阅读理解(1)|TED演讲_20岁光阴不再来

    Why 30 is not the new 20.-Meg Jay When I was in my 20s, I saw my very first psychotherapy client. I ...

  7. 20岁到30岁,是你最不可挥霍的光阴

    看了这一期TED演讲,对我触动挺大的,敲下来和大家分享一下~~~  视频链接 成人的世界里没有容易二字,每一步都算数!  when I was in my 20s, I saw my very fir ...

  8. (7)Why 30 is not the new 20

    https://www.ted.com/talks/meg_jay_why_30_is_not_the_new_20/transcript 00:12 When I was in my 20s, I ...

  9. 计算机软件专业英语考试题,计算机水平考试-软件设计师分类模拟题计算机专业英语(二)...

    计算机水平考试-软件设计师分类模拟题计算机专业英语(二) (4页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 9.9 积分 MIDI enables pe ...

最新文章

  1. php学习之道:WSDL具体解释(三)
  2. 许昌科技学校工业机器人_【调研】省人大常委会副主任徐济超到许昌科技学校进行专题调研...
  3. jQuery-Ajax
  4. 中国未来技术学院盘点
  5. Tech UP——EGO北京分会成立啦
  6. web前端培训分享Electron之IPC 通信
  7. 1059 Prime Factors(25 分)
  8. redis-数据类型-普通集合
  9. setnx是原子操作吗_Redis面试七连问,你能扛得住吗?
  10. java替换的程序_Java文本文件批量替换小程序的方法
  11. 用Ps按比例缩小图片整体的尺寸
  12. gatk过滤_GATK使用方法详解(原始数据的处理)
  13. Excel制作工资条
  14. 2022.11.15 英语背诵
  15. 超硬核万字!web前端学霸笔记,学完就去找工作吧
  16. java书号属性,基于Java的ISBN书号查询示例代码-六派数据
  17. 自编码器(Auto-encoder)的概念和应用
  18. 【思维导图】巩固你的JavaScript知识体系
  19. MSP430f2619学习—串口通信
  20. html5手机不能自动播放音乐,H5案例---解决H5中背景音乐无法自动播放问题

热门文章

  1. 第二次想上传demo到github
  2. linux不显示无线网卡驱动安装失败,Linux_Ubuntu无线网卡驱动安装方法,安装了Ubuntu后发现没有无线网 - phpStudy...
  3. 谷歌浏览器32位安装包_谷歌浏览器发布紧急安全更新修复Blink内核中的任意代码执行漏洞...
  4. java中strictfp么意思_什么时候应该在java中使用“strictfp”关键字?
  5. 微信第三方扫描登录 java源代码_微信开放平台基于网站应用授权登录源码(java)...
  6. 计算机应用技术研究生开题报告,计算机应用技术专业论文开题报告.doc
  7. java调用c jni_Java调用C JNI
  8. 华为A1路由器虚拟服务器,华为a1路由器怎么设置 华为路由器a1怎么安装视频-192路由网...
  9. php多个表中查找数据_HeidiSQL 免费的可视化数据库管理工具
  10. 海康9800平台linux的sdk,流媒体项目外包海康9800平台sdk适配