zoukankan      html  css  js  c++  java
  • hdu 5131 Song Jiang's rank list

    http://acm.hdu.edu.cn/showproblem.php?pid=5131

    题意:按照所杀的敌人排名,所杀敌人相等的时候字典序小的排名在上,然后M个询问。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <string>
     4 #include <map>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int n,k,mm;
     9 char g[500][500];
    10 int num[500];
    11 struct node
    12 {
    13     char str[500];
    14     int m;
    15     bool operator <(const node a)const
    16     {
    17         return (m>a.m)||(m==a.m&&strcmp(str,a.str)<0);
    18     }
    19 }p[100000];
    20 
    21 bool cmp(node a,node b)
    22 {
    23     return (num[a.m]<num[b.m])||(num[a.m]==num[b.m]&&strcmp(a.str,b.str)<0);
    24 }
    25 
    26 int main()
    27 {
    28      while(scanf("%d",&n)!=EOF)
    29      {
    30          if(n==0) break;
    31           map<string,int>q;
    32           for(int i=0; i<n; i++)
    33           {
    34               scanf("%s %d",g[i],&k);
    35               strcpy(p[i].str,g[i]);
    36               p[i].m=k;
    37           }
    38           sort(p,p+n);
    39           for(int i=0; i<n; i++)
    40           {
    41               num[p[i].m]++;
    42               q[p[i].str]=p[i].m;
    43           }
    44           for(int i=0; i<n; i++)
    45           {
    46               printf("%s %d
    ",p[i].str,p[i].m);
    47               q[p[i].str]=i;
    48           }
    49           scanf("%d",&mm);
    50           for(int i=1; i<=mm; i++)
    51           {
    52               char s[1000];
    53               scanf("%s",s);
    54               int cnt=0;
    55               int k=p[q[s]].m;
    56               for(int j=q[s]; j>=0; j--)
    57               {
    58                   if(p[j].m==k)
    59                   {
    60                       cnt++;
    61                   }
    62                   else break;
    63               }
    64               if(cnt==1)
    65               {
    66                   printf("%d
    ",q[s]+1);
    67               }
    68               else
    69               {
    70                   printf("%d %d
    ",q[s]+1-cnt+1,cnt);
    71               }
    72           }
    73      }
    74      return 0;
    75 }
    View Code
  • 相关阅读:
    如何判断两个数组是否相等?
    正则表达式
    开发板 Linux驱动视频 驱动是什么
    关于模型的评估
    Python画图参数设置
    Python图片的横坐标汉字
    矩阵的点成和叉乘
    svd 奇异值分解
    Python的主成分分析PCA算法
    论文参考文献格式
  • 原文地址:https://www.cnblogs.com/fanminghui/p/4227839.html
Copyright © 2011-2022 走看看