Simulation of PTA Titi competition: snatching of red packets (sort of structure) and pta snatching of Red Packets

Source: Internet
Author: User

Simulation of PTA Titi competition: snatching of red packets (sort of structure) and pta snatching of Red Packets

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 a positive integer N (≤) In the first line, 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 primary NK PK

Where K (0 ≤ K ≤ 20) is the number of sent 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
Question:

I originally wanted to use map sort, and the result was stuck with a 2-point sample. Then I changed it to structure sorting. =-=

# Include <bits/stdc ++. h> using namespace std; struct none {int id; // number int num; // number of red packets int sum; // red packet amount} man [10005]; bool cmp (none a, none B) {if (. sum> B. sum) return true; else if (. sum = B. sum) {if (. num> B. num) return true; else if (. num = B. num) {if (. sum <B. sum) return true ;}} return false ;}int main () {int I, n, k, a, B; cin >>> n; for (I = 1; I <= n; I ++) {scanf ("% d", & k); man [I]. id = I; while (k --) {scanf ("% d", & a, & B); man [a]. sum + = B; man [a]. num ++; man [I]. sum-= B ;}} sort (man + 1, man + n + 1, cmp); for (I = 1; I <= n; I ++) printf ("% d %. 2lf \ n ", man [I]. id, man [I]. sum/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.