给一些人,包括姓名(保证唯一,只有小写)和 杀人数,当杀人数相同时,按照姓名的字典序小的在前。要求先输出每个人的排序后的名字和次序。
M询问,每次询问一个人名,输出这个人的 主次序(比他杀人多的总人数+1),和 次次序(和这个人杀了相同的人里面,他排第几)。如果次次序是1,不用输出,只输出主次序
5        // 人数
WuSong 12 //人名,杀人数
LuZhishen 12 //
SongJiang 13 //
LuJunyi 1 //
HuaRong 15 //
5 // 询问数
WuSong // 比武松杀人多的有2人,2+1 = 3,和武松杀人相同的,他排第2
LuJunyi //
LuZhishen //
HuaRong //
SongJiang //
0 //
map做姓名的映射,排序即可
//Author LJH
//www.cnblogs.com/tenlee
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#define clc(a, b) memset(a, b, sizeof(a))
#define LL long long
using namespace std;
const int inf = 0x3f;
const int INF = 0x3f3f3f3f;
const int maxn = 300+5;
struct Outlaw
{
    string name;
    int minor, major;
    int num;
}outlaws[maxn];
map<string, int>mp;
bool cmp(Outlaw A, Outlaw B)
{
    if(A.num == B.num) return A.name < B.name;
    return A.num > B.num;
}
inline void print(int id)
{
    cout << outlaws[id].name << " " << outlaws[id].num << endl;
}
int main()
{
    int n;
    while(~scanf("%d", &n) && n)
    {
        mp.clear();
        for(int i = 1; i <= n; i++)
        {
            cin >> outlaws[i].name >> outlaws[i].num;
        }
        sort(outlaws+1, outlaws+n+1, cmp);
        int k = 1;
        print(1);
        mp[outlaws[1].name] = 1;
        outlaws[1].minor = 1;
        outlaws[1].major = 1;
        for(int i = 2; i <= n; i++)
        {
            print(i);
            if(outlaws[i].num == outlaws[i-1].num)
            {
                k++;
            }
            else 
            {
                k = 1;
            }
            mp[outlaws[i].name] = i;
            outlaws[i].major = i-k+1;
            outlaws[i].minor = k;
        }
        int m, id;
        string name;
        scanf("%d", &m);
        while(m--)
        {
            cin >> name;
            id = mp[name];
            if(outlaws[id].minor == 1)
            {
                printf("%d\n", outlaws[id].major);
            }
            else
            {
                printf("%d %d\n", outlaws[id].major, outlaws[id].minor);
            }
        }
    }
    return 0;
}
HDU 5131 Song Jiang's rank list(MAP)
原文:http://www.cnblogs.com/tenlee/p/4881042.html