HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)
Song Jiang's rank list
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 2006 Accepted Submission(s): 1128
In order to encourage his military officers, Song Jiang always made a rank list after every battle. In the rank list, all 108 outlaws were ranked by the number of enemies he/she killed in the battle. The more enemies one killed, one's rank is higher. If two outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now please help Song Jiang to make the rank list and answer some queries based on the rank list.
For each test case:
The first line is an integer N (0<N<200), indicating that there are N outlaws.
Then N lines follow. Each line contains a string S and an integer K(0<K<300), meaning an outlaw's name and the number of enemies he/she had killed. A name consists only letters, and its length is between 1 and 50(inclusive). Every name is unique.
The next line is an integer M (0<M<200) ,indicating that there are M queries.
Then M queries follow. Each query is a line containing an outlaw's name.
The input ends with n = 0
Then, for each name in the query of the input, print the outlaw's rank. Each outlaw had a major rank and a minor rank. One's major rank is one plus the number of outlaws who killed more enemies than him/her did.One's minor rank is one plus the number of outlaws who killed the same number of enemies as he/she did but whose name is smaller in alphabet order than his/hers. For each query, if the minor rank is 1, then print the major rank only. Or else Print the major rank, blank , and then the minor rank. It's guaranteed that each query has an answer for it.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=1e5+;
int flag[N];
struct node{
string s;
int p;
}a[N];
bool cmp(node a,node b){
if(a.p==b.p)return a.s<b.s;
else return a.p>b.p;
}
int main(){
int n,m;
while(cin>>n){
if(n==)break;
memset(flag,,sizeof(flag));
for(int i=;i<=n;i++){
cin>>a[i].s>>a[i].p;
flag[a[i].p]++;
}
sort(a+,a++n,cmp);
for(int i=;i<=n;i++)
cout<<a[i].s<<" "<<a[i].p<<endl;
cin>>m;
while(m--){
string x;
cin>>x;
for(int i=;i<=n;i++){
if(x==a[i].s){
if(flag[a[i].p]==)cout<<i<<endl;
else{
int cnt=;
for(int j=;j<=n;j++){
if(a[j].p==a[i].p&&a[j].s!=a[i].s)
cnt++;
if(a[j].s==a[i].s)break;
}
if(cnt==)cout<<i;
else cout<<i-cnt;
if(cnt+>)cout<<" "<<cnt+<<endl;
else cout<<endl;
}
}
}
}
}
return ;
}
打这一套题,就会写一个,菜哭。
HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)的更多相关文章
- HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))
周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K ( ...
- HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)
A Curious Matt Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- hdu 5131 Song Jiang's rank list
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5131 Song Jiang's rank list Description <Shui Hu Z ...
- 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list
欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 2014ACM/ICPC亚洲区广州站 北大命题
http://acm.hdu.edu.cn/showproblem.php?pid=5131 现场赛第一个题,水题.题意:给水浒英雄排序,按照杀人数大到小,相同按照名字字典序小到大.输出.然后对每个查 ...
- 2014ACM/ICPC亚洲区广州站题解
这一场各种计算几何,统统没有做. HDU 5129 Yong Zheng's Death HDU 5136 Yue Fei's Battle
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 【HDOJ】5131 Song Jiang's rank list
STL的使用. /* 5131 */ #include <iostream> #include <map> #include <cstdio> #include & ...
随机推荐
- emwin如何在windows10下vs2015或2017进行仿真。
Make sure the selected Windows SDK is installed:Properties -> Configuration Properties -> Gene ...
- HDU:2222-Keywords Search(AC自动机模板,匹配模拟)
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) P ...
- HTML插入文件链接(如音乐,照片)
html中插入音频.H5的标签 src为本地 <audio controls="> <source src="韩庚 - I Don't Give A 屑.mp3& ...
- Django基础之数据库与ORM
一.数据库配置 1.django默认支持sqlite,mysql, oracle,postgresql数据库. django默认使用sqlite的数据库,默认自带sqlite的数据库驱动 , 引擎名称 ...
- linux学习(二) -- ubuntu下lnmp环境的配置
亲测的教程,,希望能对大家提供些许帮助,转载请注明出处 ubuntu+nginx+mysql+php7 一.安装Nginx 1.首先添加nginx_signing.key(必须,否则出错) $ wge ...
- Careercup - Microsoft面试题 - 4639756264669184
2014-05-12 06:42 题目链接 原题: Write your own regular expression parser for following condition: az*b can ...
- Marketing learning-2
Part three 1.strategies for leadership 1)operational excellence:operational competence 2)performance ...
- Monkey日志信息的11种Event percentages
我们查看官方文档,表里只给出了8种事件(可以看我上篇的翻译文档).但我们运行Monkey后,却发现有11种事件!最坑爹的是,在每种事件的百分比后面,他还不给注明是什么事件! 原来不同的Android ...
- Monkey官方帮助翻译&介绍
都说想学好就看原文,英文不好为了翻译这个可费了大劲了.表格从GOOGLE官网复制到WORD里编辑,结果贴上来格式全乱了,只得不弄表格了.表格中官网的事件不是最新的,比最新的少2个,具体我会另发一篇文章 ...
- ThinkPHP5 连接 PostgreSQL
$request = Db::connect( [ 'type' => 'pgsql', 'hostname' => '127.0.0.1', 'database' => 'keyw ...