• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
不会投篮的邢
投篮三不沾
博客园    首页    新随笔    联系   管理    订阅  订阅

L2-009 抢红包 (25分)

没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。

输入格式:

输入第一行给出一个正整数N(≤),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:

N​1​​

其中K(0)是发出去的红包个数,N​i​​是抢到红包的人的编号,P​i​​(>)是其抢到的红包金额(以分为单位)。注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。

输出格式:

按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后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


/**
 * 
 */
package com.xingbing.tianti;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author 邢兵
 * @data
 * @description
 */
public class L2009 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		L2009temp arr[] = new L2009temp[n+1];
		for(int i=1;i<=n;i++){//初始化结构体
			arr[i] = new L2009temp(i, 0, 0);
		}
		for(int i=1;i<=n;i++){
			int k = in.nextInt();
			int temp[] = new int[n+1];//中间数组,用来记录这个人是否抢过红包
			for(int j=0;j<k;j++){
				int index = in.nextInt();//抢红包的人的编号
				int money = in.nextInt();//枪到的红包大小
				if(temp[index]==0){//判断这个人是否抢过红包
					arr[i].money-=money;
					arr[index].money+=money;
					temp[index]=1;
					arr[index].num++;
				}
			}
		}
		Arrays.sort(arr, 1, arr.length);
		for(int i=1;i<=n;i++){
			System.out.printf("%d %.2f", arr[i].id, arr[i].money/100.0);
			System.out.println();
		}
		
	}
}
class L2009temp implements Comparable<L2009temp>{
	public int id;
	public int money;
	public int num;
	
	public L2009temp(int id, int money, int num){
		this.id = id;
		this.money = money;
		this.num = num;
	}
	@Override
	public int compareTo(L2009temp o) {
		if(this.money<o.money)
			return 1;
		else if(this.money==o.money){
			if(this.num<o.num)
				return o.num-this.num;
			else if(this.num==o.num)
				return this.id-o.id;
			else
				return -1;
		}
		else
			return -1;
		
	}
	
}

  

posted @ 2020-01-31 22:39  不会投篮的邢  阅读(407)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3