upc组队第二场 F:MUSICAL CHAIRS)

本文解析了音乐椅游戏的编程解构,涉及玩家移动、座次变化及淘汰规则。通过C++代码展示了如何使用map和vector数据结构跟踪玩家位置,模拟比赛过程并输出结果。最后演示了如何判断赢家并处理未被淘汰者名单。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

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;	
} 

内容概要:本文档提供了关于“微型车间生产线的设计与生产数据采集试验研究”的毕业设计复现代码,涵盖从论文结构生成、机械结构设计、PLC控制系统设计、生产数据采集与分析系统、有限元分析、进度管理、文献管理和论文排版系统的完整实现。通过Python代码和API调用,详细展示了各个模块的功能实现和相互协作。例如,利用SolidWorks API设计机械结构,通过PLC控制系统模拟生产流程,使用数据分析工具进行生产数据的采集和异常检测,以及利用进度管理系统规划项目时间表。 适合人群:具有机械工程、自动化控制或计算机编程基础的学生或研究人员,尤其是从事智能制造领域相关工作的人员。 使用场景及目标:①帮助学生或研究人员快速搭建和理解微型车间生产线的设计与实现;②提供完整的代码框架,便于修改和扩展以适应不同的应用场景;③作为教学或科研项目的参考资料,用于学习和研究智能制造技术。 阅读建议:此资源不仅包含详细的代码实现,还涉及多个学科领域的知识,如机械设计、电气控制、数据分析等。因此,在学习过程中,建议读者结合实际操作,逐步理解每个模块的功能和原理,并尝试调整参数以观察不同设置下的系统表现。同时,可以参考提供的文献资料,深入研究相关理论和技术背景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值