upc组队第二场 F:MUSICAL CHAIRS)

题目描述

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 
<name> has been eliminated. 
where <name> 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 
<name> has won. 
where a single player remains, or 
Players left are <name list>. 
where the game is not yet finished.  
<name list> 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.

这个题的大概意思就是有一些人围成圈,他们都有名字,一开始有那么多板凳,给凳子编好号,他们都按顺序坐好,然后有几次移动,每一次所有人全部往前走多少步,最后让一个选择其中一个凳子的标号,让这个人离开圈,问最后谁获胜,或者多人留下的,都有谁留下,一开始我想到的就是用map 和vector 嵌套,但是苦于不会map,但是昨天刚学了个pair一样的效果,这个题要注意的是,如果一个人出圈的话,总人数要减少,并且比去掉的这个人的板凳的编号大的所有人的板凳的编号都要减一,否则会有重复的编号出现

上代码!

还有小写字母的比tm大学字母的阿斯科马值大32!!别记反了

再啰嗦一句!STL天下无敌!

#include<iostream>
#include<map>
#include<vector>
#include<cstring>
using namespace std;
vector<pair<string,int> > v;
int n,m,x,y;// x 哪个椅子  y 走几步 
string s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		v.push_back(make_pair(s,i));
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		for(int j=0;j<v.size();j++)
		{
			v[j].second=(v[j].second+y)%n;
			if(v[j].second==0)
				v[j].second=n;
		}
		int b;
		for(int k=0;k<v.size();k++)
		{
			if(v[k].second==x)
			{
				b=k;
				break;
			}
		}
		for(int i=0;i<v.size();i++)
		if(v[i].second>v[b].second)
		{
			v[i].second--;
		} 
		cout<<v[b].first<<" has been eliminated."<<endl;
		v.erase(v.begin()+b);
		n--;
	}
	if(v.size()==1)
	cout<<v[0].first<<" has won."<<endl;
	else
	{
		cout<<"Players left are";
		for(int i=0;i<v.size();i++) 
		cout<<" "<<v[i].first<<".";
	}
	return 0;	
} 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值