#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<map>
#include<iostream>
using namespace std;
struct node
{
char s[];
int v;
int flag;
int cou;
}a[];
bool cmp(node fa,node fb)
{
if(fa.v!=fb.v)
return fa.v>fb.v;
else return strcmp(fa.s,fb.s)<;
}
int main()
{
int n,m,i,j;
while(scanf("%d",&n)!=EOF)
{
map<string,int>mp;
if(!n)break;
for(i=;i<n;i++)
scanf("%s %d",a[i].s,&a[i].v);
sort(a,a+n,cmp);
int count=,index=;
for(i=;i<n;i++)
{
string ss="";
int len=strlen(a[i].s);
for(j=;j<len;j++)
ss+=a[i].s[j];
mp[ss]=i;
if(i==)
{
a[i].flag=;
a[i].cou=;
count++;
index=;
}
else
{
if(a[i].v==a[i-].v)
{
a[i].flag=count;
a[i].cou=++index;
}
else
{
a[i].flag=i+;
count=i+;
a[i].cou=;
index=;
}
}
}
for(i=;i<n;i++)
printf("%s %d\n",a[i].s,a[i].v);
scanf("%d",&m);
while(m--)
{
string ss;
cin>>ss;
if(a[mp[ss]].cou>)
{
printf("%d %d\n",a[mp[ss]].flag,a[mp[ss]].cou);
}
else printf("%d\n",mp[ss]+);
}
}
}

hdu5131 贪心的更多相关文章

  1. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  2. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  7. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. 【贪心】HDU 1257

    HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...

随机推荐

  1. HDFS的Web界面

  2. 卷积神经网络中的通道 channel

    卷积神经网络中 channels 分为三种:    (1):最初输入的图片样本的 channels ,取决于图片类型,比如RGB, channels=3    (2):卷积操作完成后输出的 out_c ...

  3. kuangbin带我飞QAQ DLX之一脸懵逼

    1. hust 1017 DLX精确覆盖 模板题 勉强写了注释,但还是一脸懵逼,感觉插入方式明显有问题但又不知道哪里不对而且好像能得出正确结果真是奇了怪了 #include <iostream& ...

  4. POJ 3122 Pie (贪心+二分)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...

  5. UVA11722 Jonining with Friend

    Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one of your ...

  6. 利用jquery模拟select效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 获得浏览器User-agent的方法

    在浏览器的地址栏输入(不是全部都能用) javascript:alert(navigator.userAgent); 或者网页中 alert(navigator.userAgent) 或者后台中 St ...

  8. spring boot resttemplate发送post,get请求

    参考博客: https://blog.csdn.net/weixin_42456466/article/details/80728387 https://www.cnblogs.com/QQParad ...

  9. linux系统服务

    系统服务分类,根据其使用的方法来分,可以被分为三类 a.由init控制的服务:基本都是系统级别的服务,运行级别这一章讲的就是这一类的服务 b.由System V启动脚本启动的服务:和我们打交道最多的一 ...

  10. NKOJ1472 警卫安排

    P1472警卫安排   时间限制 : 10000 MS   空间限制 : 65536 KB 问题描述 一个重要的基地被分为n个连通的区域.出于某种神秘的原因,这些区域以一个区域为核心,呈一颗树形分布. ...