L2-009. Grab a red envelope, l2-009 grab a red envelope

Source: Internet
Author: User

L2-009. Grab a red envelope, l2-009 grab a red envelope

No one has ever snatched a red envelope ...... Here is a record of red packets and snatching of red packets among N people. Please count the gains they have gained.

Input Format:

Enter the first line to give a positive integer N (<= 104), that is, the total number of people involved in sending and snatching red packets, then these people are numbered from 1 to N. In the next N rows, line I will show the records of red packets issued by the person numbered I, in the following format:

K N1 P1... NK PK

Where K (0 <= K <= 20) is the number of outgoing red packets, Ni is the number of the person who grabbed the red packet, Pi (> 0) is the amount of the red packet it snatched (in units ). Note: For a red envelope issued by the same person, each person can only grab one packet at most, and cannot rob again.

Output Format:

The number and income amount of each person are output in descending order of the income amount from high to low (in Yuan, the second digit after the decimal point is output ). Each person's information occupies one row and there is a space between the two numbers. If the income amount is in parallel, the return value is decreased based on the number of red packets obtained. If there is a parallel value, the return value is increased by the personal number.

Input example:

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

Output example:

1 11.632 3.638 3.633 2.117 1.696 -1.679 -2.1810 -3.265 -3.264 -12.32

Time limit 300 ms memory limit 65536 kB code length limit 8000 B discriminant program Standard author Chen Yue
#include <stdio.h>#include <stdlib.h>typedef struct{    int x;    int y;}JL;int main(){    int n;    int i, j, k = 0, pos;    int money[10001] = {0};    int id[10001] = {0};    int num[10001] = {0};    JL jl[21];    int temp;            scanf("%d", &n);        for(i = 1; i <= n; i++)    {        id[i] = i;        scanf("%d", &num[i]);        for(j = 1; j <= num[i]; j++)        {            scanf("%d %d", &jl[j].x, &jl[j].y);            money[i] -= jl[j].y;            money[jl[j].x] += jl[j].y;        }    }        for(i = 1; i <= n-1; i++)    {        pos = i;        for(j = i+1; j <= n; j++)        {            if(money[j] > money[pos])                pos = j;            if(money[j] == money[pos])            {                if(num[j] == num[pos])                {                    if(j > pos)                        pos = j;                }                if(num[j] > num[pos])                    pos = j;            }        }        if(pos != i)        {            temp = money[pos];            money[pos] = money[i];            money[i] = temp;            temp = id[pos];            id[pos] = id[i];            id[i] = temp;        }    }        for(i = 1; i <= n; i++)    {        printf("%d %.2f\n", id[i], money[i]/100.0);    }    return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.