HDU 5131 Song Jiang's rank list (结构体+MAP,2014广州现场赛)

题目链接:HDU 5131 Song Jiang‘s rank list

题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排。M个询问,询问名字输出对应的主排名和次排名。(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个数加1,(也就是杀敌数相等,但是字典序比他小的人数加1)。

AC代码:

#include <stdio.h>
#include <string>
#include <map>
#include <string.h>
#include <algorithm>
using namespace std;

struct node
{
	char name[100];
	int num;
};
struct node p[310];

map<string,int> rak1;
map<string,int> rak2;

bool cmp(node a,node b)
{
	if(a.num!=b.num)
		return a.num>b.num;
	return strcmp(a.name,b.name)<0;
}

int main()
{
	int n,m,i,j;
	while(scanf("%d",&n)!=EOF,n)
	{
		rak1.clear();
		rak2.clear();
		for(i=0;i<n;i++)
			scanf("%s %d",p[i].name,&p[i].num);
		sort(p,p+n,cmp);
		int temp=p[0].num,cont=1,rr=0;
		rak1[p[0].name]=cont;
		for(i=0;i<n;i++)
			printf("%s %d\n",p[i].name,p[i].num);
		for(i=0;i<n;i++)
		{
			cont=0;
			for(j=0;j<i;j++)
			{
				if(p[i].num<p[j].num)
					cont++;
			}
			rak1[p[i].name]=cont+1;
		}
		for(i=0;i<n;i++)
		{
			cont=0;
			for(j=0;j<i;j++)
			{
				if(p[i].num==p[j].num)
					cont++;
			}
			rak2[p[i].name]=cont+1;
		}
		scanf("%d",&m);
		while(m--)
		{
			char quy[100];
			scanf("%s",quy);
			if(rak2[quy]==1)
				printf("%d\n",rak1[quy]);
			else
				printf("%d %d\n",rak1[quy],rak2[quy]);
		}
	}
	return 0;
}

HDU 5131 Song Jiang's rank list (结构体+MAP,2014广州现场赛)

时间: 2024-12-24 14:19:52

HDU 5131 Song Jiang's rank list (结构体+MAP,2014广州现场赛)的相关文章

HDU 5131 Little Zu Chongzhi&#39;s Triangles (状压DP +2014广州现场赛)

题目链接:HDU 5131 Little Zu Chongzhi's Triangles 题意:给出一些线段,在其中选出3根组成三角形,问用这些线段组成的所有三角形的最大面积是多少. 7 3 4 5 3 4 5 90 两个三角形是(3,3,4),(5,5,4). 思路:N最大12,状态压缩,把所有可能组成的三角形存起来.A&B==0则说明A|B状态是有效的. 贪心也能过..为什么? AC代码: #include <stdio.h> #include <string.h> #

[ACM] HDU 5131 Song Jiang&#39;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): 36    Accepted Submission(s): 18 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'an

hdu 5131 Song Jiang&#39;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): 662    Accepted Submission(s): 329 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

hdu 5131 Song Jiang&#39;s rank list

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5131 Song Jiang's rank list 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

HDU 5131 Song Jiang&#39;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): 264    Accepted Submission(s): 137 Problem Description <Shui Hu Zhuan>,also <Water Margin&

HDU 5131 Song Jiang&#39;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): 259    Accepted Submission(s): 134 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

hdu 5131 Song Jiang&#39;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): 253    Accepted Submission(s): 128 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

HDU 5218 The E-pang Palace (简单几何—2014广州现场赛)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题面: The E-pang Palace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 1646    Accepted Submission(s): 1226 Problem Description E-pang Palac

hdu 5137 去掉一个点 使得最短路最大(2014广州区域赛K题)

题意:从2~n-1这几个点中任意去掉一个点,使得从1到n的最短路径最大,如果任意去掉一个点1~n无通路输出Inf. Sample Input4 51 2 31 3 71 4 502 3 43 4 23 21 2 302 3 100 0 Sample Output50Inf 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 #