L2-2 抢红包 (25 分)
没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。
输入格式:
输出格式:
按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。每个人的信息占一行,两数字间有1个空格。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。
输入样例:
10
3 2 22 10 58 8 125
5 1 345 3 211 5 233 7 13 8 101
1 7 8800
2 1 1000 2 1000
2 4 250 10 320
6 5 11 9 22 8 33 7 44 10 55 4 2
1 3 8800
2 1 23 2 123
1 8 250
4 2 121 4 516 7 112 9 10
输出样例:
1 11.63
2 3.63
8 3.63
3 2.11
7 1.69
6 -1.67
9 -2.18
10 -3.26
5 -3.26
4 -12.32
#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#define ll long long
using namespace std;
struct data
{
int num;
int sum;
int money;
}a[10101];
bool cmp(data x, data y)
{
if (x.money == y.money)
return x.sum > y.sum;
return x.money > y.money;
}
int main()
{
int n, m, x, y;
while(~scanf("%d", &n))
{
for (int i = 0;i <= n;i ++)
{
a[i].num = i;
a[i].sum = 0;
a[i].money = 0;
}
for (int i = 1;i <= n;i ++)
{
scanf("%d", &m);
for (int j = 0;j < m;j ++)
{
scanf("%d%d", &x, &y);
a[i].money -= y;
a[x].money += y;
a[x].sum += 1;
}
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1;i <= n;i ++)
printf("%d %.2f\n", a[i].num, a[i].money * 1.0 / 100);
}
return 0;
}