HDU5131-Song Jiang's rank list HDU5135-Little Zu Chongzhi's Triangles(大佬写的)
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 ;
}
打这一套题,就会写一个,菜哭。
HDU5131-Song Jiang's rank list HDU5135-Little Zu Chongzhi's Triangles(大佬写的)的更多相关文章
- hdu5135 Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...
- Song Jiang's rank list
Song Jiang's rank list Time Limit:1000MS Memory Limit:512000KB 64bit IO Format:%I64d & ...
- 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 ...
- 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 ...
- UVALive 7077 - Song Jiang's rank list(模拟)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【HDOJ】5131 Song Jiang's rank list
STL的使用. /* 5131 */ #include <iostream> #include <map> #include <cstdio> #include & ...
- 局域网象棋游戏(C++实现,使用Socket,界面使用Win32,CodeBlocks+GCC编译)
目录 成果 运行效果图 过程 1. 首先的问题是下棋的两端应该是什么样的? 2. 接下来的问题是怎么表示,怎么存储? 3. 然后应该怎么通信呢? 代码 main.cpp chinese_chess.h ...
- c++转义字符、指针
上篇博客的答案: 1: // DataTypeDemo.cpp : 定义控制台应用程序的入口点. 2: // 3: 4: #include "stdafx.h" 5: #incl ...
随机推荐
- Python 项目实践二(生成数据)第二篇之随机漫步
接着上节继续学习,在本节中,我们将使用Python来生成随机漫步数据,再使用matplotlib以引人瞩目的方式将这些数据呈现出来.随机漫步是这样行走得到的路径:每次行走都完全是随机的,没有明确的方向 ...
- The Movie db (TMDB)的API申请
在共享API TMDB中申请时,一只报错Application summary please elaborate on how you plan to use our API,我是用汉字描述的,开始以 ...
- 对Spring与SpringMVC的理解
Spring 在我的Spring --简介及环境搭建跑通Hello提到关于Spring的基本结构与功能 SpringMVC 先上一张SpringMVC的流程图 Spring MVC 是一个模型 - 视 ...
- bzoj 3669: [Noi2014] 魔法森林 LCT版
Description 为了得到书法大家的真传,小E同学下定决心去拜访住在魔法森林中的隐士.魔法森林可以被看成一个包含个N节点M条边的无向图,节点标号为1..N,边标号为1..M.初始时小E同学在号节 ...
- My Go Resolutions for 2017(from Russ cox's blog)
我的2017年Go决议 一年之季始于春,我认为写一些今年我希望在Go上做的东西是有意义的. 我每年的目标是帮助Go开发人员.我想确保我们在Go团队中所做的工作对Go开发者有重大的积极影响.可能听起来很 ...
- 【深度学习系列】一起来参加百度 PaddlePaddle AI 大赛吧!
写这个系列写了两个月了,对paddlepaddle的使用和越来越熟悉,不过一直没找到合适的应用场景.最近百度搞了个AI大赛,据说有四个赛题,现在是第一个----综艺节目精彩片段预测 ,大家可以去检测一 ...
- Python第二十二天 stat模块 os.chmod方法 os.stat方法 pwd grp模块
Python第二十二天 stat模块 os.chmod方法 os.stat方法 pwd grp模块 stat模块描述了os.stat(filename)返回的文件属性列表中各值的意义,根据 ...
- 使用sed,grep 批量修改文件内容
使用sed命令可以进行字符串的批量替换操作,以节省大量的时间及人力: 使用的格式如下: sed -i "s/oldstring/newstring/g" `grep oldstri ...
- Django__RBAC
RBAC : 基于角色的权限访问控制(Role-Based Access Control) RBAC 模型作为目前最为广泛接受的权限模型 角色访问控制(RBAC)引入了Role的概念,目的是为了隔离U ...
- windows10合并分区
删除无用分区 将分区D合并到分区C,"计算机"---右键"管理"--"磁盘管理" 点击分区名,右键选择删除卷,如果有数据,提前备份 扩展分区 ...