首页 > 学院 > 开发设计 > 正文

5-9 抢红包 (25分)

2019-11-06 07:21:45
字体:
来源:转载
供稿:网友
***[点击获取原题链接](https://pta.patest.cn/pta/test/3604/exam/4/question/52083)*** 5-9 抢红包 (25分)没有人没抢过红包吧…… 这里给出NNN个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。输入格式:输入第一行给出一个正整数NNN(≤104/le 10^4≤10​4​​),即参与发红包和抢红包的总人数,则这些人从1到NNN编号。随后NNN行,第iii行给出编号为iii的人发红包的记录,格式如下:KN1P1⋯NKPKK/quad N_1/quad P_1/quad /cdots/quad N_K/quad P_KKN​1​​P​1​​⋯N​K​​P​K​​其中KKK(0≤K≤200 /le K /le 200≤K≤20)是发出去的红包个数,NiN_iN​i​​是抢到红包的人的编号,Pip_iP​i​​(>0>0>0)是其抢到的红包金额(以分为单位)。注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。输出格式:按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。每个人的信息占一行,两数字间有1个空格。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。输入样例:103 2 22 10 58 8 1255 1 345 3 211 5 233 7 13 8 1011 7 88002 1 1000 2 10002 4 250 10 3206 5 11 9 22 8 33 7 44 10 55 4 21 3 88002 1 23 2 1231 8 2504 2 121 4 516 7 112 9 10输出样例:1 11.632 3.638 3.633 2.117 1.696 -1.679 -2.1810 -3.265 -3.264 -12.32时间限制:400ms内存限制:64MB代码长度限制:16kB 判题程序:系统默认作者:陈越单位:浙江大学题目判定/// 一样的代码一开始0分 后来满分 不知道什么问题 如果发现先问题 请指正 感激不尽#include <bits/stdc++.h>using namespace std;struct node{ double data; int id; int count;} a[10000+100];int cmd(struct node a,struct node b)///比较函数{ if(a.data != b.data) return a.data > b.data;///红包降续 else if(a.count != b.count) return a.count > b.count ;/// 红包更额数 降续 else if(a.id != b.id) return a.id < b.id ;/// 用户编号升序}int main(){ int N; scanf("%d",&N);///N个人发红包 for(int i=0; i<=N; i++) { a[i].data=0; a[i].count=0; a[i].id=i; } for(int i=1; i<=N; i++)///输入数据 { int t; scanf("%d",&t); double sum=0; for(int j=1; j<=t; j++) { int id; scanf("%d",&id); double count=0; scanf("%lf",&count); a[id].data+=count/100.0;/// 从“分” 转换成“元” a[id].count++; sum+=count; } a[i].data-=sum/100.0; } sort(a+1,a+N+1,cmd);///快排 for(int i=1; i<=N; i++) { PRintf("%d %.2lf/n",a[i].id,a[i].data); } return 0;}/********输入样例:103 2 22 10 58 8 1255 1 345 3 211 5 233 7 13 8 1011 7 88002 1 1000 2 10002 4 250 10 3206 5 11 9 22 8 33 7 44 10 55 4 21 3 88002 1 23 2 1231 8 2504 2 121 4 516 7 112 9 10输出样例:1 11.632 3.638 3.633 2.117 1.696 -1.679 -2.1810 -3.265 -3.264 -12.32**********/
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表