L2-009. 抢红包

来源:互联网 发布:人工智能在安防行业 编辑:程序博客网 时间:2024/04/28 09:52

L2-009. 抢红包

时间限制
300 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越

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

输入格式:

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

K N1 P1 ... NK PK

其中K(0 <= K <= 20)是发出去的红包个数,Ni是抢到红包的人的编号,Pi(> 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
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>using namespace std;struct nod{    int r;    int jin;}a[10002];struct node{    int r;    int jin;    int q;}c[10002];bool cmp(struct node x,struct node y){    if(x.jin!=y.jin)    return x.jin>y.jin;    else if(x.q!=y.q)    return x.q<y.q;    else    return x.r >y.r;}int b[10001];double sum[10001];int main(){    int n,m,i,j;    memset(b,0,sizeof(b));    memset(sum,0,sizeof(sum));    scanf("%d",&n);    for(i = 0;i < n; i++)    {        scanf("%d",&m);        for(j = 0;j < m; j++)        {            scanf("%d %d",&a[j].r,&a[j].jin);            sum[i] = sum[i]-a[j].jin;            b[a[j].r]++;            sum[a[j].r-1] = sum[a[j].r-1]+a[j].jin;        }    }    for(i = 0;i < n; i++)    {        c[i].jin = sum[i];        c[i].r = i;        c[i].q = b[i];    }    sort(c,c+n,cmp);    for(i = 0;i < n; i++)    {        printf("%d %.2lf\n",c[i].r+1,(double)c[i].jin/100);    }}
这个题是个难度一般的题,(当然对我来说的),这个题主要是让我认识到double不能作比较。。。
代码菜鸟,如有错误,请多包涵!!
0 0