天梯 抢红包

没什么思维难度 就是知道结构体排序即可

注释较为详细

#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 10100;
//自定义规则
bool cmp(pair<int, pair<double, int>> a, pair<int, pair<double, int>> b)
{
	if (a.second.first == b.second.first)
	{
		if (a.second.second == b.second.second)
			return a.first < b.first;
		return a.second.second > b.second.second;
	}
	return a.second.first > b.second.first;
}
	//直接用的pair结构体 
	//就是它本身就蕴含着两个元素 就是省事了
	//默认第一个是first 第二个是second
	pair<int, pair<double, int>> x[MAX_N];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		int m;
		scanf("%d", &m);
		x[i].first = i;
		while (m--)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			//抢的人的余额
			x[a].second.first += b;
			//发红包人的余额
			x[i].second.first -= b;
			//抢的个数
			x[a].second.second++;
		}
	}
	//因为是从1开始的 就多加了个1
	sort(x, x + n + 1, cmp);

	for (int i = 0; i <= n; ++i)
	{
		//下标从1开始的
		if (x[i].first == 0)
			continue;
		printf("%d %.2f\n", x[i].first, x[i].second.first / 100);
	}

	return 0;
}
发布了106 篇原创文章 · 获赞 25 · 访问量 7215

猜你喜欢

转载自blog.csdn.net/weixin_45653525/article/details/104295819