2014ACM/ICPC 广州赛区E题 (水~)

Song Jiang‘s rank list

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

Total Submission(s): 0    Accepted Submission(s): 0

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

简单题。。

不多说了(泪啊)

要注意排序函数不能用strcmp,我记得以前用可以,,估计我记错了,诶

AC代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#define LL long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;

struct node
{
    char name[105];
    int num;
    int major, minor;
}out[210];

bool cmp(node a, node b)
{
    if(a.num!=b.num)return a.num>b.num;
    else
        for(int i=0; ;)
        {
            if(a.name[i]!=b.name[i])return a.name[i]<b.name[i];
            else i++;
        }
}

int main()
{
    int n, m;
    while(scanf("%d", &n), n)
    {
        for(int i=0; i<n; i++)
        {
            scanf("%s %d", out[i].name, &out[i].num);
            out[i].major=1; out[i].minor=1;
        }
        sort(out, out+n, cmp);
        for(int i=0; i<n; i++)
        {
            printf("%s %d\n", out[i].name, out[i].num);
        }
        int rank = 1;
        for(int i=1; i<n; i++)
        {
            rank++;
            if(out[i].num==out[i-1].num)
            {
                out[i].major = out[i-1].major;
                out[i].minor = out[i-1].minor+1;
            }
            else out[i].major = rank;
        }
        scanf("%d", &m);
        for(int i=0; i<m; i++)
        {
            char b[105];
            scanf("%s", b);
            for(int j=0; j<n; j++)
            {
                if(strcmp(b, out[j].name)==0)
                {
                    if(out[j].minor==1)
                        printf("%d\n", out[j].major);
                    else
                        printf("%d %d\n", out[j].major, out[j].minor);
                    break;
                }
            }
        }
    }
    return 0;
}
时间: 2024-10-17 21:22:24

2014ACM/ICPC 广州赛区E题 (水~)的相关文章

ZOJ 3820 2014ACM/ICPC牡丹江赛区B题

3797714 2014 - 10 - 12 21:58 : 19 Accepted 3820 C++ 1350 70240 zz_1215 比较麻烦的一道题吧,开始的时候不停的段异常,后面知道是爆栈了,然后用数组模拟递归,才ac了 思路挺简单的,先找到这个树的直径,单独拿出来,可以证明最后选的两个点一定是在直径上的,我就不证了 然后求出这条直径上的每个点向外延伸的最远距离 对这个距离做两次RMQ,第一次是对于往左边计算最大距离,所以要这个距离的序列要依次+1,+2,+3.......+n-1,

[hdu5136]Yue Fei&#39;s Battle 2014 亚洲区域赛广州赛区J题(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下午有点事情,无法打重现,所以下午只是花了十分钟做了一道J题,抢了个FB,2333333333 Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)T

【解题报告】2014ACM/ICPC上海赛区现场赛B

唉  谷歌出的神题,差点爆零了...三小时终于A掉 B题 题目大概是说从左上角的点出发,经过某路线最后回到原点,求每个格子被路线包含的圈数的平方和. 首先可以知道,对于某个格子来说,从该格子的任意一个方向划一条射线,路径穿过该射线的次数就等于该格子被包含的圈数(正穿和反穿抵消). 然后开一个100w的数组保存每个格子的上面那条线被向右走过的次数.模拟出路径,然后填满数组.求格子的圈数就等于这个格子和它上面所有格子里面填的值的和.然后全部平方加起来就可以了. 有一个点就是可以把高和宽中较短的那一条

zoj 3662 第37届ACM/ICPC长春赛区H题(DP)

题目:给出K个数,使得这K个数的和为N,LCM为M,问有多少种 f[i][j][k]表示选i个数,总和为j,最小公倍数为k memery卡的比较紧,注意不要开太大,按照题目数据开 这种类型的dp也是第一次做 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue&g

hdu 4462 第37届ACM/ICPC 杭州赛区 J题

题意:有一块n*n的田,田上有一些点可以放置稻草人,再给出一些稻草人,每个稻草人有其覆盖的距离ri,距离为曼哈顿距离,求要覆盖到所有的格子最少需要放置几个稻草人 由于稻草人数量很少,所以状态压缩枚举,之后慢慢判断即可,注意放稻草人的格子是不需要覆盖的 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath>

hdu 4461 第37届ACM/ICPC杭州赛区I题

题意:给两个人一些棋子,每个棋子有其对应的power,若b没有或者c没有,或者二者都没有,那么他的total power就会减1,total power最少是1,求最后谁能赢 如果b或c出现的话,flag就标记为1,那么在判断的时候如果flag==0,就说明他们没出现过,那么就要-1,然后就wa了,必须要两个变量判断,不知道为什么 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #inclu

hdu 4463 第37届ACM/ICPC杭州赛区K题 最小生成树

题意:给坐标系上的一些点,其中有两个点已经连了一条边,求最小生成树的值 将已连接的两点权值置为0,这样一定能加入最小生成树里 最后的结果加上这两点的距离即为所求 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map>

2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集

传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个信息是不冲突的. 思路:首先很明显的我们要维护一系列不知道的信息, 看冲不冲突的那就是带权并查集没跑了, 此时r[v] 表示v到这棵树的根节点(虽然题目没给, 但是我们可以假设一个)的路径异或和, 那么此时的每条信息相当于是告诉你r[u] ^ r[v]的值, 注意异或的特性. 所以对于每条信息维护好

2014ACM/ICPC亚洲区鞍山赛区现场赛——题目重现

2014ACM/ICPC亚洲区鞍山赛区现场赛--题目重现 题目链接 5小时内就搞了5题B.C.D.E,I. H题想到要打表搞了,可惜时间不够,后面打出表试了几下过了- - K题过的人也比较多,感觉是个几何旋转+ploya,但是几何实在不行没什么想法 B:这题就是一个大模拟,直接数组去模拟即可,注意细节就能过 C:类似大白上一题红蓝三角形的, 每个数字找一个互质和一个不互质个数,除掉重复就直接除2,然后总的C(n, 3)减去即可,问题在怎么处理一个数字互质和不互质的,其实只要处理出不互质的即可,这