The Song Dynasty historian Sima Guang in "the Capital Governance Tong Jian" has a famous "The Moral Only Theory": "is therefore only then the virtuous all says the sage, only then the German and the death is the Fool, the German wins only then is said the gentleman, only then wins the moral to be the villain. Whoever takes the technique of the person, Gou not saints, gentleman and with it, with the villain, not if the fool. ”
Now give a number of candidates of the German score, please according to Sima Guang theory to give admission rankings.
Input format:
Enter the 1th line to give 3 positive integers, namely: N (<=105), that is, the total number of candidates, L (>=60), for the admission of the minimum score, that is, the German and want $ are not less than L candidates are eligible to be considered for admission; H (<100), the priority line of admission-- The German and want $ are not below this line is defined as "only de full", such candidates by virtue of the total score from high to low ranking; want $, but the German division to the line of a class of candidates belonging to the "Desheng", but also according to the total number of candidates, but ranked in the first category after the candidate, Germany want $ are lower than H, but the score is not less than want $ candidates belong to "only Germany and death" "De Sheng", ranked by total, but ranked after the second category of candidates, other people who reached the minimum line L were ranked by total, but ranked after the third category of candidates.
Then n lines, each line gives a candidate's information, including: The ticket number, German points, want $, where the ticket number is a 8-bit integer, Germany is divided into the interval [0, 100] integer. The numbers are separated by a space.
Output format:
Output line 1th first gives the number of candidates to reach the minimum fraction m, followed by M, each line in the input format to output a candidate's information, candidates according to the rules indicated in the input from high to low sort. When a certain number of candidates in the same time, according to their German points in descending order; If the German points are also tied, the ticket number in the ascending output.
Input Sample:
14 60 8010000001 64 9010000002 90 6010000011 85 8010000003 85 8010000004 80 8510000005 82 7710000006 83 7610000007 90 7810 000008 75 7910000009 59 9010000010 88 4510000012 80 10010000013 90 9910000014 66 60
Sample output:
1210000013 90 9910000012 80 10010000003 85 8010000011 85 8010000004 80 8510000007 90 7810000006 83 7610000005 82 771000000 2 90 6010000014 66 6010000008 75 7910000001 64 90
Idea: It's better to put a student in four combinations. #include <algorithm> using namespace std; bool CMP (struct student a,struct student B)
1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 intn,l,h;5 structStudent6 {7 intId;8 intDe;9 intCai;Ten intsum; One} student[100010]; A //Sort - BOOLcmpstructStudent A,struct -Student B)//Why to add a const the { - //first of all, according to Integrity - //Caide do - if(a.de>=h&&a.cai>=h&&b.de>=h&&b.cai>=h)//similar + { - if(a.sum==b.sum) + { A if(a.de==b.de) at returna.id<b.id; - Else - returnA.de>b.de; - } - Else - returnA.sum>b.sum; in } - Else if(a.de>=h&&a.cai>=H) to { + return true; - } the Else if(b.de>=h&&b.cai>=H) * { $ return false;Panax Notoginseng } - Else if(a.de>=h&&a.caiH) the { + if(a.sum==b.sum) A { the if(a.de==b.de) + returna.id<b.id; - Else $ returnA.de>b.de; $ } - Else - returnA.sum>b.sum; the } - Else if(a.de>=h&&a.cai<H)Wuyi { the return true; - } Wu Else if(b.de>=h&&b.cai<H) - { About return false; $ } - Else if(a.de>=l&&a.deB.cai) - { - if(a.sum==b.sum) A { + if(a.de==b.de) the returna.id<b.id; - Else $ returnA.de>b.de; the } the Else the returnA.sum>b.sum; the } - Else if(a.de>=l&&a.deA.cai) in { the return true; the } About Else if(b.de>=l&&b.deB.cai) the { the return false; the } + Else - { the if(a.sum==b.sum)Bayi { the if(a.de==b.de) the returna.id<b.id; - Else - returnA.de>b.de; the } the Else the returnA.sum>b.sum; the } - the } the the 94 the the intMainintargcChar**argv) { the intCount=0;//number of people who have reached the minimum fraction98scanf"%d%d%d",&n,&l,&H); About for(intI=0; i<n;i++) - {101scanf"%d%d%d", &student[i]. Id,&student[i]. de,&Student[i]. Cai);102Student[i].sum=student[i]. De+Student[i]. Cai;103 if(Student[i]. de<l| | Student[i]. cai<L)104 { thei--;106n--;107 } 108 109 Else thecount++;111 } theSort (student,student+count,cmp);113printf"%d\n", count); the for(intI=0; i<count;i++) theprintf"%d%d%d\n", Student[i]. Id,student[i]. De,student[i]. Cai); the return 0;117}
View Code
PAT1015. The moral Theory (25)