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 ;
}

打这一套题,就会写一个,菜哭。

HDU5131-Song Jiang's rank list HDU5135-Little Zu Chongzhi's Triangles(大佬写的)的更多相关文章

  1. hdu5135 Little Zu Chongzhi's Triangles

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...

  2. Song Jiang's rank list

     Song Jiang's rank list Time Limit:1000MS     Memory Limit:512000KB     64bit IO Format:%I64d & ...

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

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

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

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

  6. UVALive 7077 - Song Jiang's rank list(模拟)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

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

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

  8. 局域网象棋游戏(C++实现,使用Socket,界面使用Win32,CodeBlocks+GCC编译)

    目录 成果 运行效果图 过程 1. 首先的问题是下棋的两端应该是什么样的? 2. 接下来的问题是怎么表示,怎么存储? 3. 然后应该怎么通信呢? 代码 main.cpp chinese_chess.h ...

  9. c++转义字符、指针

    上篇博客的答案: 1: // DataTypeDemo.cpp : 定义控制台应用程序的入口点. 2: // 3:  4: #include "stdafx.h" 5: #incl ...

随机推荐

  1. 云计算之路-阿里云上-2017年最错误的选择: 生产环境使用 docker swarm

    2017年12月29日 10:18 ~ 11:00 左右,由于整个 docker swarm 集群宕机,造成我们迁移至 .net core 跑在 docker swram 上的所有站点无法正常访问,由 ...

  2. 【Zookeeper】源码分析之服务器(一)

    一.前言 前面已经介绍了Zookeeper中Leader选举的具体流程,接着来学习Zookeeper中的各种服务器. 二.总体框架图 对于服务器,其框架图如下图所示 说明: ZooKeeperServ ...

  3. Qt--自定义Delegate

    这是Model/View中的最后一篇了,Qt官方显然弱化了Controller在MVC中的作用,提供了一个简化版的Delegate:甚至在Model/View框架的使用中,提供了默认的委托,让这个控制 ...

  4. Wincc的使用

    1.组态项目步骤 1)启动Wincc 2)建立项目 3)选择及安装通信驱动程序 4)定义变量 5)建立和编辑过程画面 6)指定Wincc运行系统的属性 7)激活Wincc画面 8)使用变量模拟器测试过 ...

  5. C语言_第二讲_规范以及常用数据类型

    一丶编码规范基本数据类型 编码规范 任何程序员,都应该有良好的的编码习惯,便于以后的代码可读性和维护 常见了编码规范有 匈牙利命名法 驼峰式大小写 匈牙利命名法: 是电脑程序设计中的一种变量命名规则, ...

  6. UVA 10559 Blocks

    题目大意:有一串带颜色的方块,每次可以消掉颜色相同的一段,得到size^2的分数,问最多能得到多少分数.n≤200. 给这题状态跪下来. 显然的区间DP,但设f[i][j]是不够的. 考虑到之前做过的 ...

  7. PredictionIO+Universal Recommender快速开发部署推荐引擎的问题总结(2)

    1, 对Universal Recommender进行pio build成功,但是却提示No engine found Building and delpoying model [INFO] [Eng ...

  8. lesson - 4 Linux目录文件管理

    内容概要:1. 和目录相关的几个命令mkdir 关注-p选项 rmdir 同样也有一个-p选项rm -r -f 两个常用选项cp -r 针对目录, 有时我们使用/bin/cpmv 重命名或者移动, 有 ...

  9. sudo 做不到的事

    本文是经验帖,以后遇到类似的情况会持续更新到这篇文章 普通用户使用sudo会遇到以下情况 1.字符流无法写入到 /var/log/messages /var/log/secure (实际上这些文件一旦 ...

  10. Golang 网络爬虫框架gocolly/colly 二 jQuery selector

    Golang 网络爬虫框架gocolly/colly 二 jQuery selector colly框架依赖goquery库,goquery将jQuery的语法和特性引入到了go语言中.如果要灵活自如 ...