Arithmetic problem: The moral theory

Source: Internet
Author: User

Title Description

The Song Dynasty historian Sima Guang in "the Capital Governance Tong Jian" has a well-known "the Moral Only Theory": "is therefore only then the virtuous all says the sage, only then the German and the Dead is the Fool, the German wins only then says the gentleman, only then wins the moral

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 Description:

Enter the 1th line to give 3 positive integers: 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

is considered to be admitted, H (<100), for the priority line--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 overall ranking, but ranked in the first category after the candidates, Germany want $ are lower than H, but no less than want $ candidates belong to "only Germany and

"But there are" Desheng ", ranked by total, but ranked after the second category of candidates, and 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 Description:

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 there are more than one type of candidate

The total score is at the same time, in descending order according to their German points;

Input Example:
14 60 80

10000001 64 90

10000002 90 60

10000011 85 80

10000003 85 80

10000004 80 85

10000005 82 77

10000006 83 76

10000007 90 78

10000008 75 79

10000009 59 90

10000010 88 45

10000012 80 100

10000013 90 99

10000014 66 60

Output Example:

12

10000013 90 99

10000012 80 100

10000003 85 80

10000011 85 80

10000004 80 85

10000007 90 78

10000006 83 76

10000005 82 77

10000002 90 60

10000014 66 60

10000008 75 79

10000001 64 90

#include <iostream>#include <map>#include <string.h>using namespace STD; Programme I: WithMap。structnode{Char*schoolnum;intLdata;intHdata; Node () {} node (Const Char*STR,intLinth): Schoolnum (New Char[strlen(str) +1])    {strcpy(Schoolnum, str);        Ldata = l;    Hdata = h; }};structcheigh{BOOL operator() (Node Nd1, node Nd2) {if(Nd1. Ldata +nd1. Hdata) > (Nd2. Hdata + Nd2. Ldata)) {return true; }Else{if(Nd1. Ldata + nd1. Hdata) < (Nd2. Hdata + Nd2. Ldata))return false;Else{return string(Nd1.schoolnum) >string(Nd2.schoolnum);//Q. If the score is the same, you have to compare the study number. }        }    }};Template<TypeNameT1,TypeNameT2,TypeNameT3>voidPrintf ( map<T1,T2,T3>&AMP;MP) { map<node, int>:: Iterator it = Mp.begin (); while(It! = Mp.end ()) {cout<< It->first.schoolnum <<" "<< It->first. Ldata <<" "<< It->first.        Hdata << Endl;    it++; }}intMain () { map<node, int,cheigh>MP1;//Caide the best.      map<node, int,cheigh>MP2;//Victory only.      map<node, int,cheigh>mp3;//Virtue and death "but still have" de wins.      map<node, int,cheigh>mp4;//other students.    intNintNUML, NUMH;Cin>> n >> numl >> numh;intCount = N;Char*inputstr =New Char[Ten];intA, B; while(n--) {Cin>> Inputstr >> a >> b;if(A >= numl && b >= numl) {if(A >= numh && b >= numh)                {Node SNode (inputstr, A, b); Mp1.insert (Pair<node,int> (SNode,0)); }Else if(A >= numh && B < NUMH)                {Node SNode (inputstr, A, b); Mp2.insert (Pair<node,int> (SNode,0)); }Else if(A < NUMH && B < numh && B <= a)                {Node SNode (inputstr, A, b); Mp3.insert (Pair<node,int> (SNode,0)); }Else{Node SNode (inputstr, A, b); Mp4.insert (Pair<node,int> (SNode,0)); }        }Else{count--; }    }cout<< Count << Endl; Printf<node,int,cheigh> (MP1); Printf<node,int,cheigh> (MP2); Printf<node,int,cheigh> (mp3); Printf<node,int,cheigh> (MP4);return 0;} Scenario Two: Custom heap.#include <iostream>#include <string.h>using namespace STD;structnode{Char*schoolnum;intLdata;intHdata; Node () {} node (Const Char*STR,intLinth): Schoolnum (New Char[strlen(str) +1])    {strcpy(SCHOOLNUM,STR);        Ldata = l;    Hdata = h; }BOOL operator< (ConstNode nd) {if((Ldata + Hdata) < (nd. Hdata + nd. Ldata)) {return true; }Else{if((Ldata + hdata) > (nd. Hdata + nd. Ldata))return false;Else{return string(Schoolnum) <string(Nd.schoolnum);//Q. If the score is the same, you have to compare the study number. }        }    }friendostream&operator<< (Ostream &_o,ConstNode &od) {_o << od.schoolnum <<" "<< od. Ldata <<" "<< od. Hdata << Endl;return_o; }};Template<TypeNameType>classHeap { Public: Heap (intN): Heap (NewNode[n]) {size =0; }voidInsert (Type &val) {heap[size++] = val;intn = size/2; while(n>=0) {setnew (heap,n);//Adjustment. n--; }    }voidSetnew (Node *heap,intN) {inti = n;intj =2* i +1; while(J < size) {if(j +1< size && Heap[j] < Heap[j +1]) {j = j + +; }if(Heap[i] < heap[j])                {Node temp = heap[i];                Heap[i] = Heap[j];            HEAP[J] = temp;            } i = J; j = i *2+1; }    }voidPrintf () { while(size) {cout<< heap[0] << Endl; heap[0] = heap[size-1];            size--; Setnew (Heap,0);//Forget to adjust, find a half-day error. }    }Private: Type *heap;intsize;};intMain () {intNintNUML, NUMH;Cin>> n >> numl >> numh; Heap<node> HP1 (n);//Caide the best. Heap<node> HP2 (n);//Victory only. Heap<node> hp3 (n);//Virtue and death "but still have" de wins. Heap<node> HP4 (n);//other students.    intCount = N;Char*inputstr =New Char[Ten];intA, B; while(n--) {Cin>> Inputstr >> a >> b;if(A >= numl && b >= numl) {if(A >= numh && b >= numh)                {Node SNode (inputstr,a,b); Hp1.            Insert (SNode); }Else if(A >= numh && B < NUMH)                {Node SNode (inputstr, A, b); Hp2.            Insert (SNode); }Else if(A < NUMH && B < numh && B <= a)                {Node SNode (inputstr,a,b); Hp3.            Insert (SNode); }Else{Node SNode (inputstr, A, b); Hp4.            Insert (SNode); }        }Else{count--; }    }cout<< Count << Endl; Hp1.    Printf (); Hp2.    Printf (); Hp3.    Printf (); Hp4. Printf ();return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Arithmetic problem: The moral theory

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.