萌新来求助,第九个点过不了,比目标所求答案序号小一
查看原帖
萌新来求助,第九个点过不了,比目标所求答案序号小一
794396
chenpursuit楼主2024/5/8 16:52
# include <iostream>
# include <vector>
# include <algorithm> // sort()
# define endl '\n'
//# define pII pair <int,int>
//const int N = 20;
using namespace std;
class Player
{
public:
	int num;
	int grade;
	int ability;
};

void contest(Player &a,Player &b)//实力高的得分  注意使用传址形参,传值不能修改分数,可以使用指针或者引用
{
	if (a.ability > b.ability)
		a.grade =a.grade+1;
	else
		b.grade =b.grade+1;
}
bool my_cmp(Player a,Player b)//分高排前面
{
	if (a.grade > b.grade) return true;
	if (a.grade < b.grade) return false;
	if (a.grade == b.grade) return a.num < b.num;
}

signed main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, r, q; cin >> n >> r >> q;
	vector<Player> player(2*n + 1);
	for (int i = 0; i < 2 * n; i++)
	{
		cin >> player[i].grade;
		player[i].num = i+1;//编号比i多1
	}
	for (int i = 0; i < 2 * n; i++)
	{
		cin >> player[i].ability;
	}
	stable_sort(player.begin() , player.end(), my_cmp);//排出第一轮的对决
	for (int i = 1; i <= r; i++)//R轮对决
	{
		for (int j = 0;j <= 2 * n - 2;j+=2)
		{
			int z = j + 1;
			contest(player[j], player[z]);//奇数排名与偶数排名对决
		}
		stable_sort(player.begin() , player.end(), my_cmp);//每轮结束重新排名
	}
	cout << player[q-1].num << endl;
	return 0;
}

2024/5/8 16:52
加载中...