zoukankan      html  css  js  c++  java
  • 2014年广州区域赛e题解

    2014年广州区域赛e题解

    笺释

    因为不用维护,所以读进来之后放在结构体数组里排序就好,排序方式是杀人数相同就按照字典序(string自带的),杀人数不同就杀人多的排前面嘛。
    然后用一个map存一下string和排序位置int的对应关系,拿到要query的string之后直接输出就好了

    #include<bits/stdc++.h>
    using namespace std;
    struct hero
    {
        int kill;
        string name;
    }heros[205];
    bool cmp(hero h1,hero h2)
    {
        if(h1.kill==h2.kill)
        {
            return h1.name<h2.name;
        }
        else
        {
            return h1.kill>h2.kill;
        }
    }
    int n,m;
    string query;
    map<string,int>mp;
    int main()
    {
        while(~scanf("%d",&n),n)
        {
            for(int i=1;i<=n;i++)
            {
               cin>>heros[i].name;
                cin>>heros[i].kill;
            }
            sort(heros+1,heros+1+n,cmp);
            for(int i=1;i<=n;i++)
            {
                cout<<heros[i].name<<" ";
                cout<<heros[i].kill<<endl;
                mp[heros[i].name]=i;
            }
            scanf("%d",&m);
            while(m--)
            {
                cin>>query;
                int index=mp[query];
                int num=0;
                for(int i=index;heros[i].kill==heros[index].kill;i--)
                {
                    num++;
                }
                if(num==1)
                {
                    printf("%d
    ",index-num+1);
                }
                else
                {
                    printf("%d %d
    ",index-num+1,num);
                }
            }
        
            mp.clear();
        }
    }
    
  • 相关阅读:
    赛前一个月
    Barricade---hdu5889(最短路+网络流)
    Tea---hdu5881(规律)
    The Best Path---hdu5883(欧拉路径)
    Cure---hdu5879(打表+找规律)
    Python列表操作
    Zabbix在Docker中的应用和监控
    flannel网络设置
    Volume
    Service资源清单
  • 原文地址:https://www.cnblogs.com/SoniciSika/p/9034199.html
Copyright © 2011-2022 走看看