Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=5131
Song Jiang ' s rank listdescription
"Shui Hu Zhuan", also "water Margin" was written by Shi Nai's "an"-an writer of Yuan and Ming dynasty. "Shui Hu Zhuan" is one of the four great classical novels of Chinese literature. It tells a story about 108 outlaws. They came from different backgrounds (including scholars, fishermen, Imperial drill instructors etc.), and all of them eve Ntually came to occupy Mout Liang (or Liangshan Marsh) and elected Song Jiang as their leader.
In order to encourage he military officers, Song Jiang always made a rank list after every battle. The rank list, all 108 outlaws were ranked by the number of enemies he/she killed in the battle. The more enemies one killed, one's rank is higher. If Outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now, help Song Jiang to make the rank list and answer some queries based on the rank list.
Input
There is no more than test cases.
For each test case:
The first line is a integer n (0<n<200), indicating that there be n outlaws.
Then N lines follow. Each line contains a string S and a integer K (0<k<300), meaning an outlaw ' s name and the number of enemies he/she h Ad killed. A name consists only letters, and its length is between 1 and (inclusive). Every name is unique.
The next line is a integer m (0<m<200), indicating that there is M queries.
Then M queries follow. Each query was a line containing an outlaw ' s name.
The input ends with n = 0
Output
For each test case, print the Rank list first. For the contains a outlaw ' s name and the number of enemies he killed.
Then, for each name in the query of the input, print the Outlaw ' s rank. Each outlaw had a major rank and a minor rank. One ' s major rank is one plus the number of outlaws who killed more enemies than him/her did. One ' s minor rank is one plus the number of outlaws who killed the same number of enemies as he/she do but whose name is S Maller in Alphabet order than his/hers. For each query, if the minor rank was 1, then print the major rank only. Or else Print The major rank, blank, and then the minor rank. It's guaranteed that each query has a answer for it.
Sample Input
5
Wusong 12
Luzhishen 12
Songjiang 13
Lujunyi 1
Huarong 15
5
Wusong
Lujunyi
Luzhishen
Huarong
Songjiang
0
Sample Output
Huarong 15
Songjiang 13
Luzhishen 12
Wusong 12
Lujunyi 1
3 2
5
3
1
2
STL Dafa:
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <string>8#include <map>9#include <Set>Ten usingstd::cin; One usingstd::cout; A usingStd::endl; - usingStd::find; - usingStd::sort; the usingSTD::Set; - usingStd::map; - usingstd::p air; - usingstd::vector; + usingSTD::string; - usingStd::multiset; + usingStd::multimap; A #definePB (E) push_back (e) at #defineSZ (c) (int) (c). Size () - #defineMP (A, b) Make_pair (A, B) - #defineAll (c) (c). Begin (), (c). End () - #defineITER (c) Decltype ((c). Begin ()) - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) in #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) to Const intN = About; +typedef unsignedLong Longull; -map<string,int>A; themap<int,Set<string> >B; * structNode { $ intVal;Panax Notoginseng stringname; -InlineBOOL operator< (ConstNode &a)Const { the returnval = = A.val? Name < A.name:val >A.val; + } A }rec[n]; the intMain () { + #ifdef LOCAL -Freopen ("In.txt","R", stdin); $Freopen ("OUT.txt","w+", stdout); $ #endif -Std::ios::sync_with_stdio (false); - intN, M; the stringbuf; - while(~SCANF ("%d", &n) &&N) {Wuyi a.clear (), B.clear (); the Rep (i, N) { -CIN >> Rec[i].name >>Rec[i].val; WuA[rec[i].name] =Rec[i].val; - B[rec[i].val].insert (rec[i].name); About } $Sort (REC, rec +n); -Rep (i, N) cout << rec[i].name <<" "<< Rec[i].val <<Endl; -CIN >>m; - while(m--) { ACIN >>buf; + intV, ans1 =1, Ans2 =1; thev =A[buf]; -TR (A, i)if(I->second > V) ans1++; $TR (B[v], i)if(*i < BUF) ans2++; the if(1= = Ans2) printf ("%d\n", ans1); the Elseprintf"%d%d\n", ans1, ans2); the } the } - return 0; in}
View Code
HDU 5131 Song Jiang ' s rank list