zoukankan      html  css  js  c++  java
  • HDU 5131 Song Jiang's rank list(MAP)

    题目链接:

    戳我

    题目大意:

    给一些人,包括姓名(保证唯一,只有小写)和 杀人数,当杀人数相同时,按照姓名的字典序小的在前。要求先输出每个人的排序后的名字和次序。

    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
    ", outlaws[id].major);
                }
                else
                {
                    printf("%d %d
    ", outlaws[id].major, outlaws[id].minor);
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    struts 中 s:iterator 使用注意事项
    redmine 2.5.2 安装后邮件无法发送
    yum提示another app is currently holding the yum lock;waiting for it to exit
    UVA 11809 Floating-Point Numbers
    UVA 1587 Box
    UVA 1583 Digit Generator
    UVA 340 Master-Mind Hints
    UVA 401 Palindromes
    UVA 11175 From D to E and Back
    洛谷P3916 图的遍历
  • 原文地址:https://www.cnblogs.com/tenlee/p/4881042.html
Copyright © 2011-2022 走看看