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

Problem Description
《Shui Hu Zhuan》,also 《Water Margin》was written by Shi Nai'an -- an writer of Yuan and Ming dynasty. 《Shui Hu Zhuan》is one of the Four Great Classical Novels of Chinese literature. It tells a story about 108 outlaws. They came from different backgrounds (including scholars, fishermen, imperial drill instructors etc.), and all of them eventually came to occupy Mout Liang(or Liangshan Marsh) and elected Song Jiang as their leader.

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.

 
Input
There are no more than 20 test cases.

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

 
Output
For each test case, print the rank list first. For this part in the output ,each line contains an outlaw's name and the number of enemies he killed.

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.

 
Sample Input
5
WuSong 12
LuZhishen 12
SongJiang 13
LuJunyi 1
HuaRong 15
5
WuSong
LuJunyi
LuZhishen
HuaRong
SongJiang
0
 
Sample Output
HuaRong 15
SongJiang 13
LuZhishen 12
WuSong 12
LuJunyi 1
3 2
5
3
1
2
 
 
 
代码:
 #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亚洲区广州站-重现赛)的更多相关文章

  1. HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))

    周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others)    Memory Limit: 512000/512000 K ( ...

  2. 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 ...

  3. HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)

    A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) ...

  4. 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 ...

  5. 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list

    欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  6. 2014ACM/ICPC亚洲区广州站 北大命题

    http://acm.hdu.edu.cn/showproblem.php?pid=5131 现场赛第一个题,水题.题意:给水浒英雄排序,按照杀人数大到小,相同按照名字字典序小到大.输出.然后对每个查 ...

  7. 2014ACM/ICPC亚洲区广州站题解

    这一场各种计算几何,统统没有做. HDU 5129 Yong Zheng's Death HDU 5136 Yue Fei's Battle

  8. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. 【HDOJ】5131 Song Jiang's rank list

    STL的使用. /* 5131 */ #include <iostream> #include <map> #include <cstdio> #include & ...

随机推荐

  1. Python基础闯关失败总结

    对列表进行创建切片增删改查 对列表进行创建 L1 = []  # 定义L1 为一个空列表 List() #创建List 空列表 对列表进行查询 L2 = ['a','b','c','d','a','e ...

  2. Python 包导入

    首先我们先了解下python中寻找模块的顺序 是否是内建模块 ->主目录 ->PYTHONPATH环境变量 ->标准库 -> 首先判断这个model是否是built-in,即内 ...

  3. Fragment 和 Activity 之间通信

    在 Activity 中获取 Fragment 实例: FragmentManager 提供了一个类似于 findViewById 的方法,专门用于从布局文件中获取 Fragment 实例: //通过 ...

  4. 在windows64位上安装Python3.0

    1.下载安装包 下载地址:https://www.python.org/downloads/ 如果要下载帮助文件:Download Windows help file 如果要下载基于网页的安装程序: ...

  5. rule.xml属性概念

    # tableRule <tableRule name="rule1"> <rule> <columns>id</columns> ...

  6. UVALive 5099 Nubulsa Expo 全局最小割问题

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  7. selenium webdriver——鼠标事件

    Web产品中提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在WebDriver中,将这些关于鼠标操作的方法 封装在ActionChains类中: ActionChains类 ...

  8. ruby linux连接windows执行dos命令

    在整个开发流程中,gitlab-runner-ci是搭建在linux下.web自动化是在windows下面进行的. 如果ci构建完版本.部署完后,需要触发启动自动化执行. 那么我们需要在部署完后在li ...

  9. MySQL误操作后如何快速恢复数据?

    摘要: 利用binlog闪回误操作数据. 基本上每个跟数据库打交道的程序员(当然也可能是你同事)都会碰一个问题,MySQL误操作后如何快速回滚?比如,delete一张表,忘加限制条件,整张表没了.假如 ...

  10. 一道背包神题-Petrozavodsk Winter-2018. Carnegie Mellon U Contest Problem I

    题目描述 有\(n\)个物品,每个物品有一个体积\(v_i\),背包容量\(s\).要求选一些物品恰好装满背包且物品个数最少,并在这样的方案中: (1)求出中位数最小的方案的中位数(\(k\)个元素的 ...