{"id":552,"date":"2013-09-06T20:25:44","date_gmt":"2013-09-06T12:25:44","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=552"},"modified":"2013-09-06T20:25:44","modified_gmt":"2013-09-06T12:25:44","slug":"1062-talent-and-virtue-25","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=552","title":{"rendered":"1062. Talent and Virtue (25)"},"content":{"rendered":"<p>About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people&#8217;s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a &#8220;sage\uff08\u5723\u4eba\uff09&#8221;; being less excellent but with one&#8217;s virtue outweighs talent can be called a &#8220;nobleman\uff08\u541b\u5b50\uff09&#8221;; being good in neither is a &#8220;fool man\uff08\u611a\u4eba\uff09&#8221;; yet a fool man is better than a &#8220;small man\uff08\u5c0f\u4eba\uff09&#8221; who prefers talent than virtue.<br \/>\nNow given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang&#8217;s theory.<br \/>\n<b>Input Specification:<\/b><br \/>\nEach input file contains one test case. Each case first gives 3 positive integers in a line: N (&lt;=10<sup>5<\/sup>), the total number of people to be ranked; L (&gt;=60), the lower bound of the qualified grades &#8212; that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (&lt;100), the higher line of qualification &#8212; that is, those with both grades not below this line are considered as the &#8220;sages&#8221;, and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the &#8220;noblemen&#8221;, and are also ranked in non-increasing order according to their total grades, but they are listed after the &#8220;sages&#8221;. Those with both grades below H, but with virtue not lower than talent are considered as the &#8220;fool men&#8221;. They are ranked in the same way but after the &#8220;noblemen&#8221;. The rest of people whose grades both pass the L line are ranked after the &#8220;fool men&#8221;.<br \/>\nThen N lines follow, each gives the information of a person in the format:<\/p>\n<pre>ID_Number Virtue_Grade Talent_Grade<\/pre>\n<p>where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.<br \/>\n&nbsp;<br \/>\n<b>Output Specification:<\/b><br \/>\nThe first line of output must give M (&lt;=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID&#8217;s.<br \/>\n<b>Sample Input:<\/b><\/p>\n<pre>14 60 80\n10000001 64 90\n10000002 90 60\n10000011 85 80\n10000003 85 80\n10000004 80 85\n10000005 82 77\n10000006 83 76\n10000007 90 78\n10000008 75 79\n10000009 59 90\n10000010 88 45\n10000012 80 100\n10000013 90 99\n10000014 66 60<\/pre>\n<p><b>Sample Output:<\/b><\/p>\n<pre>12\n10000013 90 99\n10000012 80 100\n10000003 85 80\n10000011 85 80\n10000004 80 85\n10000007 90 78\n10000006 83 76\n10000005 82 77\n10000002 90 60\n10000014 66 60\n10000008 75 79\n10000001 64 90<\/pre>\n<p>======================================================<br \/>\n\u6b64\u9898\u5c31\u662f\u4e2a\u5206\u51e0\u7c7b\u7136\u540e\u6392\u5e8f\u7684\u95ee\u9898\uff0c\u5c06\u6bcf\u4e2a\u4eba\u4f5c\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u7528STL\u5c31\u5f88\u597d\u505a\u4e86<br \/>\n\u91cd\u8f7d\u4e00\u4e0b\u8fd0\u7b97\u7b26&lt;\u5c31\u884c\u4e86\uff0cSTL\u7684sort\u7528\u5b83\u6765\u6392\u5e8f\u7684&#8230;<br \/>\n\u5207\u8bb0\u6bd4\u8f83\u6807\u51c6\u7684\uff08\u4eceC++\u57fa\u7840\u6559\u7a0b\u4e0a\u627e\u5230\u7684\uff09\u5c0f\u4e8e\u8fd0\u7b97\u7b26\u91cd\u8f7d\u7684\u89c4\u8303<br \/>\n<code lang=\"c++\"><br \/>\nbool operator<( const Object &#038;obj) const;\n<\/code><br \/>\n\u6ca1\u5565\u96be\u5ea6\u5566~\u5c31\u662f\u6709\u70b9\u8d39\u65f6\u95f4<br \/>\n<code lang=\"c++\"><br \/>\n#include <algorithm><br \/>\n#include <stdio.h><br \/>\n#include <vector><br \/>\nusing namespace std;<br \/>\nstruct Person<br \/>\n{<br \/>\n\tlong id;<br \/>\n\tint talent;<br \/>\n\tint virtue;<br \/>\n\tPerson(long _id, int _vir, int _tal)<br \/>\n\t{<br \/>\n\t\tid = _id;<br \/>\n\t\ttalent = _tal;<br \/>\n\t\tvirtue = _vir;<br \/>\n\t}<br \/>\n\tbool operator<( const Person&#038; p) const\n\t{\n\t\tbool flag;\n\t\t\/\/Overload operator <\n\t\tint total_self = talent + virtue;\n\t\tint total_him = p.talent + p.virtue;\n\t\tif(total_self < total_him)\n\t\t\tflag = true;\n\t\telse if(total_self > total_him)<br \/>\n\t\t\tflag = false;<br \/>\n\t\telse<br \/>\n\t\t{<br \/>\n\t\t\tif(virtue == p.virtue)<br \/>\n\t\t\t\tflag = id > p.id; \/\/ID in increasin order!<br \/>\n\t\t\telse<br \/>\n\t\t\t\tflag = virtue < p.virtue;\n\t\t}\n\t\treturn !flag; \/\/Non-increasing order\n\t}\n};\nint main()\n{\n\tvector<person> people[4];<br \/>\n\tint N, L, H;<br \/>\n\tscanf(\"%d %d %d\", &N, &L, &H);<br \/>\n\tint M = 0;<br \/>\n\tfor(int i=0; i<n; i++)\n\t{\n\t\tlong id;\n\t\tint tal, vir;\n\t\tscanf(\"%ld %d %d\", &#038;id, &#038;vir, &#038;tal);\n\t\tif(tal <l || vir < L)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tM++;\n\t\tPerson p(id, vir, tal);\n\t\tif(tal >=H && vir >= H)<br \/>\n\t\t{<br \/>\n\t\t\t\/\/Sage<br \/>\n\t\t\tpeople[0].push_back(p);<br \/>\n\t\t}<br \/>\n\t\telse if(vir >= H)<br \/>\n\t\t{<br \/>\n\t\t\t\/\/Nobleman<br \/>\n\t\t\tpeople[1].push_back(p);<br \/>\n\t\t}<br \/>\n\t\telse if(vir >= tal)<br \/>\n\t\t{<br \/>\n\t\t\t\/\/Fool<br \/>\n\t\t\tpeople[2].push_back(p);<br \/>\n\t\t}<br \/>\n\t\telse<br \/>\n\t\t{<br \/>\n\t\t\t\/\/Small man<br \/>\n\t\t\tpeople[3].push_back(p);<br \/>\n\t\t}<br \/>\n\t}<br \/>\n\tprintf(\"%dn\", M);<br \/>\n\tfor(int i=0; i<4; i++)\n\t{\n\t\t\/\/Arrange them\n\t\tsort(people[i].begin(), people[i].end());\n\t\t\/\/Output\n\t\tfor(vector<person>::iterator it=people[i].begin(); it!=people[i].end(); it++)<br \/>\n\t\t{<br \/>\n\t\t\tprintf(\"%ld %d %dn\", it->id, it->virtue, it->talent);<br \/>\n\t\t}<br \/>\n\t}<br \/>\n\treturn 0;<br \/>\n}<br \/>\n<\/code><\/p>\n<pre>\n\u6d4b\u8bd5\u70b9\t\u7ed3\u679c\t\u7528\u65f6(ms)\t\u5185\u5b58(kB)\t\u5f97\u5206\/\u6ee1\u5206\n0\t\u7b54\u6848\u6b63\u786e\t0\t710\t12\/12\n1\t\u7b54\u6848\u6b63\u786e\t0\t710\t2\/2\n2\t\u7b54\u6848\u6b63\u786e\t40\t990\t3\/3\n3\t\u7b54\u6848\u6b63\u786e\t80\t3730\t3\/3\n4\t\u7b54\u6848\u6b63\u786e\t80\t3800\t3\/3\n5\t\u7b54\u6848\u6b63\u786e\t0\t790\t2\/2\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people&#8217;s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a &#8220;sage\uff08\u5723\u4eba\uff09&#8221;; being less excellent but with one&#8217;s virtue outweighs talent can be called a &#8220;nobleman\uff08\u541b\u5b50\uff09&#8221;; being good [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[84],"class_list":["post-552","post","type-post","status-publish","format-standard","hentry","category-study","tag-pat"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=552"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/552\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}