2014广州亚洲现场赛/HDU 5131 Song Jiang's rank list(水题)

2024-03-30 05:48

本文主要是介绍2014广州亚洲现场赛/HDU 5131 Song Jiang's rank list(水题),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Song Jiang's rank list

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 1746    Accepted Submission(s): 983


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

Source
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)

题意:给定N个人的姓名和他的杀敌数,然后按照杀敌数从大到小排序,数值相同的,名字字典序小的排在前。

然后先把排序的结果输出。

再来M个询问,每个询问是查询某个人的排名,排名由两部分构成。第一部分是求出杀敌数比他大的人数+1,第二部分是跟他杀敌数相同但排名比他靠前的人数+1,如果第二部分的答案是1,则不用输出。

N和M都不过200,于是水题一枚,对于询问直接暴力扫就行了。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
#include <stdlib.h>
#define lowbit(x) (x&-x)
#define e exp(1.0)
//ios::sync_with_stdio(false);
//    auto start = clock();
//    cout << (clock() - start) / (double)CLOCKS_PER_SEC;
typedef long long ll;
typedef long long LL;
using namespace std;
struct node
{string name;int num;int ranks;
}a[305];
int pos[305];
int cmp(const node &a,const node &b)
{if(a.num==b.num)return a.name<b.name;return a.num>b.num;
}
int main()
{int n;while(cin>>n && n){memset(pos,0,sizeof(pos));for(int i=0;i<n;i++){cin>>a[i].name>>a[i].num;pos[a[i].num]++;}sort(a,a+n,cmp);for(int i=0;i<n;i++)cout<<a[i].name<<' '<<a[i].num<<endl;int ans=0;int k;cin>>k;string s;while(k--){ans=0;cin>>s;int number;for(int i=0;i<n;i++)if(a[i].name==s)number=a[i].num;for(int i=0;i<n;i++){if(a[i].num>number)ans++;}cout<<ans+1;ans=0;for(int i=0;i<n;i++){if(a[i].name<s && a[i].num==number)ans++;}if(ans)cout<<" "<<ans+1;cout<<endl;}}return 0;
}

这篇关于2014广州亚洲现场赛/HDU 5131 Song Jiang's rank list(水题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/860641

相关文章

-bash: /bin/mv: Argument list too long mv

把labels下的所有文件mv到img文件夹下: mv labels/* img/ 报错: -bash: /bin/mv: Argument list too long  mv # Using find ... -exec + find folder2 -name '*.*' -exec mv --target-directory=folder '{}' +   # Using xar

Java零基础-集合:List

哈喽,各位小伙伴们,你们好呀,我是喵手。运营社区:C站/掘金/腾讯云;欢迎大家常来逛逛   今天我要给大家分享一些自己日常学习到的一些知识点,并以文字的形式跟大家一起交流,互相学习,一个人虽可以走的更快,但一群人可以走的更远。   我是一名后端开发爱好者,工作日常接触到最多的就是Java语言啦,所以我都尽量抽业余时间把自己所学到所会的,通过文章的形式进行输出,希望以这种方式帮助到更多的初

CSS列表属性:list-style系列属性详解

CSS(层叠样式表)是用于控制网页样式的一种语言,它允许开发者以一种非常灵活的方式来设置网页元素的外观。在CSS中,list-style属性族是专门用来设置列表样式的。列表是网页设计中常见的元素,它们可以是有序列表(<ol>)或无序列表(<ul>)。list-style系列属性允许你自定义列表项前的标记,包括类型、位置和图像。 1. list-style-type list-style-typ

上海邀请赛 A题目 HDU 5236(dp)

先求出没有ctrl+s的时候构造长度为i的期望f[i] 。然后枚举保存的次数,求出最小即可。 #include<cstdio>#include<cstdio>#include<cmath>#include<queue>#include<stack>#include<string>#include<cstring>#include<iostream>#include<map>

hdu 2586 树上点对最近距离 (lca)

,只要知道dis[i][j]=dis[i][root]+dis[j][root]-2*dis[Lca(i,j)][root].   其中root为树的根节点,LCA(i,j)为i,j的最近公共祖先。 所以我们先把所有的询问储存下来,然后离线直接查询。复杂度是o(n+q)的。 VIE #include<cstdio>#include<algorithm>#include<i

Google Code Jam 2014(附官方题解)

2014年Google编程挑战赛 Problem A. Magic Trick Confused? Read the quick-start guide. Small input 6 points You have solved this input set. Note: To advance to the next rounds, you will need to s

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

玩转Web之Json(四)---json与(Object/List/Map)的相互转化

在做web应用时,经常需要将json转化成Object/list/map或者将Object/List/map转化成json,通过简单封装可以在写代码是减轻很多负担。本文将给出json转化的一系列方法。 闲话不 多说,直接上代码: 先是Object /List /Map转化为Json /* 功能 :将一个对象转成json数组* 参数 :object对象* retu

【C++11 之新增容器 array、foward_list、tuple、unordered_(multi)map/set】应知应会

C++11 标准中新增了多个容器,这些容器为 C++ 程序员提供了更多的选择,以满足不同的编程需求。以下是对这些新容器的介绍和使用案例: std::array 介绍: std::array 是一个固定大小的数组容器,它在栈上分配内存,并提供了类似于标准库容器的接口。它提供了更好的类型安全性和范围检查,同时保持了与原生数组相似的性能。std::array 的大小必须在编译时确定,并且不能更改。

论坛开发者总结:再见2013,你好2014!

转自:http://www.cocoachina.com/gamedev/misc/2014/0102/7644.html 在跨年的时候,我和你一样听着电视里的各种欢呼声,看着时针分针不慌不忙地走向0点,有点兴奋有点怅然有点对过往的追忆也有对未来的期许,但在0点钟声敲响的时候,不管过往如何,都信心满满地对自己说了声--你好2014! 对于开发者来说,2013年移动游