2020年7月PAT甲级真题 The Judger

题目

题意:

首先给出两个数字,然后n名选手,m轮比赛,每轮比赛n名选手分别给出自己的数字,数字要求不能与前面出现过的重复,并且必须是前面出现的任意两个数之差,否则直接在第i轮比赛淘汰第j名选手,被淘汰的选手的后面比赛的数字直接忽略,最后升序输出胜出者。


tips:set+模拟

#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	int n,m;
	cin>>n>>m;
	set<int>temp;
	set<int> count;
	temp.insert(abs(a-b));
	int ans[n][m];
	count.insert(a);
	count.insert(b);
	for(int i=0; i<n; ++i)
		for(int j=0; j<m; ++j) {
			cin>>ans[i][j];
		}
	vector<int>check(n,0);
	for(int i=0; i<m; ++i) {
		for(int j=0; j<n; ++j) {
			if(!check[j]) {
				int flag=0;
				if(count.find(ans[j][i])==count.end())//判断重复。
					for(auto it : count) {
						if(temp.find(ans[j][i])!=temp.end()) {//判断是否为数字之差
							flag=1;
							break;
						}
					}
				if(!flag) {
					cout<<"Round #"<<i+1<<": "<<j+1<<" is out.\n";
					check[j]=1;
				} else {
					for(auto it : count) {
						temp.insert(abs(ans[j][i]-it));
					}
				}
				count.insert(ans[j][i]);
			}
		}
	}
	int flag=0;
	for(int i=0; i<n; ++i)
		if(!check[i]) {
			if(!flag) {
				cout<<"Winner(s): "<<i+1;
				flag=1;
			} else cout<<" "<<i+1;
		}
	if(!flag)
		cout<<"No winner.";
}

 

 

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大章鱼(张文哲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值