hdu 5038 Grade 简单题 2014 ACM/ICPC Asia Regional Beijing Online

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038

Problem Description
Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushrooms and ask him to grade each mushroom according to its weight. Suppose the weight of a mushroom is w, then it’s grade s is

s = 10000 - (100 - w)^2

What’s more, Ted also has to report the mode of the grade of these mushrooms. The mode is the value that appears most often. Mode may not be unique. If not all the value are the same but the frequencies of them are the same, there is no mode.
 

Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

The first line of each test cases contains one integers N (1<=N<=10^6),denoting the number of the mushroom.

The second line contains N integers, denoting the weight of each mushroom. The weight is greater than 0, and less than 200.
 

Output
For each test case, output 2 lines.

The first line contains "Case #x:", where x is the case number (starting from 1)

The second line contains the mode of the grade of the given mushrooms. If there exists multiple modes, output them in ascending order. If there exists no mode, output “Bad Mushroom”.
 

Sample Input
  
  
3 6 100 100 100 99 98 101 6 100 100 100 99 99 101 6 100 100 98 99 99 97
 

Sample Output
  
  
Case #1: 10000 Case #2: Bad Mushroom Case #3: 9999 10000
 

Source


题意懂了就好做了,刚开始读错题意了...

给你一个w,根据公式算出一个s值,求s频率最高的,可能不唯一...如果所有的s的频率一样,但是w不全相同,那么输出“Bad Mushroom”..否则升序输出s

代码:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>

using namespace std;

#define min2(x, y)     min(x, y)
#define max2(x, y)     max(x, y)
#define min3(x, y, z)  min(x, min(y, z))
#define max3(x, y, z)  max3(x, max(y, z))
#define clr(x, y)      memset(x, y, sizeof(x))
#define fr(i,n)        for(int i = 0; i < n; i++)
#define fr1(i,n)       for(int i = 1; i < n; i++)
#define upfr(i,j,n)    for(int i = j; i <= n; i++)
#define dowfr(i,j,n)   for(int i = n; i >= j; i--)
#define scf(n)         scanf("%d", &n)
#define scf2(n,m)      scanf("%d %d",&n,&m)
#define scf3(n,m,p)    scanf("%d %d %d",&n,&m,&p)
#define ptf(n)         printf("%d",n)
#define ptf64(n)       printf("%I64d",n)
#define ptfs(s)        printf("%s",s)
#define ptln()         printf("\n")
#define ptk()          printf(" ")
#define ptc(c)         printf("%c",c)
#define srt(a,n)       sort(a,n)
#define LL long long
#define pi acos(-1.0)
#define inf 1 << 31-1
#define eps 0.00001
#define maxn 205
#define maxm 10005
#define mod 10000007

struct  node
{
	int num;
	int value;
}mode[maxn];
int hash[maxm];
int ans[maxn];
int cmp(node a, node b)
{
	if(a.num == b.num)
		return a.value < b.value;
	return a.num > b.num;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int t;
	scf(t);
	int ca = 1;
	while(t--)
	{
		printf("Case #%d:\n", ca++);
		clr(hash, 0);
		clr(ans, 0);
		clr(mode, 0);
		int n;
		scf(n);
		int cnt = 1;
		fr(i, n)
		{
			int w;
			int s;
			scf(w);
			s = 10000 - (100 - w) * (100 - w);
			if(hash[s] == 0)
			{
				mode[cnt].value = s;
				mode[cnt].num ++;
				hash[s] = cnt;
				cnt ++;
			}
			else
				mode[hash[s]].num ++;
		}
		if(cnt == 2)
		{
			printf("%d\n", mode[1].value);
			continue;
		}
		sort(mode+1, mode+1+cnt, cmp);
		int cnt2 = 0;
		upfr(i, 1, cnt)
		{
			if(mode[1].num == mode[i].num)
				ans[cnt2 ++] = mode[i].value;
			else
				break;
		}
		if(cnt2 == cnt - 1)
			printf("Bad Mushroom\n");
		else
		{
			ptf(ans[0]);
			fr1(i, cnt2)
			ptk(),ptf(ans[i]);
			ptln();
		}
		/*fr1(i, cnt)
		printf("%d %d\n", mode[i].num, mode[i].value);*/
	}
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值