Grab a red envelope arithmetic problem

Grab a red envelope arithmetic problem

problem

Here are given red envelopes each other N individuals, grab a red envelope record, you look at the statistics they harvest grab a red envelope.

Entry

The first line gives a positive integer N (≤10 ^ 4), i.e., the total number of participating grab red and red hair, these people numbered from 1 to N. Then N rows, the i-th row number i given person recording red envelopes, each line has the form: K N1 P1 ⋯ NK PK where K (0≤K≤20) number is sent to the red, Ni grab red envelopes to people's numbers, Pi (> 0) is its grab the red envelope amount (to be divided into units). Note: For the same individual issued a red envelope, each person can only grab one time, can not be repeated looting.

Export

The output of each person's number and the amount of revenue in descending order of decreasing the amount of revenue (in dollars after the two units, output decimal point). Each person's information per line, there is a space between the two numbers. If there are tied for the amount of revenue, the number of press to grab a red envelope falling output; if there are side by side, pressing personal number is incremented output.

Sample input

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

Sample Output

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

Code

#include<iostream>
#include<algorithm> 
using namespace std;
//count int max = 10010;

struct people
{
	int money; //总钱数
	int num; //抢红包个数
	int hao; //存序号
}p[10010];

bool cmp(people a,people b)
{
	if(a.money==b.money) return a.num>b.num;
	else return a.money>b.money;
}

int main()
{
	int n,m,ren,qian;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		p[i].hao = i;
		p[i].money = 0;
		p[i].num = 0;
	}
	for(int i=0;i<n;i++)
	{
		
		cin>>m;
		for(int j=0;j<m;j++)
		{
			cin>>ren>>qian;
			p[ren].money += qian; 
			p[ren].num ++;
			p[i+1].money -= qian; //发钱的人减少
		}
	}
	sort(p+1,p+n+1,cmp); // 从1开始存入的,所以初始为p+1,左闭右开,结束为 p+n+1
	double shu;
	for(int i=1;i<=n;i++)
	{
		shu = (double)p[i].money / 100;
		printf("%d %.2f\n",p[i].hao,shu);
	}
	return 0;
} 
发布了11 篇原创文章 · 获赞 1 · 访问量 260

Guess you like

Origin blog.csdn.net/weixin_42408097/article/details/104410105