</pre>Grade</h1><strong><span style="font-family:Arial; color:green">Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 801 Accepted Submission(s): 399</span></strong><div class="panel_title" align="left" style="height:38px; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold">Problem Description</div><div class="panel_content" style="height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'; text-align:left">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 <center><strong>s = 10000 - (100 - w)^2</strong></center>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.</div><div class="panel_bottom" style="height:auto; margin:0px"> </div><div class="panel_title" align="left" style="height:38px; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold">Input</div><div class="panel_content" style="height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'; text-align:left">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.</div><div class="panel_bottom" style="height:auto; margin:0px"> </div><div class="panel_title" align="left" style="height:38px; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold">Output</div><div class="panel_content" style="height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'; text-align:left">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”.</div><div class="panel_bottom" style="height:auto; margin:0px"> </div><div class="panel_title" align="left" style="height:38px; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold">Sample Input</div><div class="panel_content" style="height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'; text-align:left"><pre style="word-wrap:break-word; white-space:pre-wrap; margin-top:0px; margin-bottom:0px"><div style="font-family:'Courier New',Courier,monospace">3
6
100 100 100 99 98 101
6
100 100 100 99 99 101
6
100 100 98 99 99 97</div>
|
题目就是要根据输入的w值,来算出s值,并把输出频率最多的s值(可以为多组),但如果出现多组频率s值,并且总数的等于输入的总数,则判为坏蘑菇;(比如有6组w,s值分别为1000、1000、999、999、998、998,平率相等的有3组,并且总数为6,则为坏蘑菇)
#include <stdio.h> #include <math.h> #include <algorithm> int main() { int n,w,i,m,d,t,max,c,sign,k,a[110]; while(scanf("%d",&n)!=EOF) { t=0; while(n--) { memset(a,0,sizeof(a)); scanf("%d",&m); t++; max=-1; c=0; sign=0; k=m; while(m--) { scanf("%d",&w); a[abs(100-w)]++; } for(i=0;i<=100;i++) { if(a[i]>max) max=a[i]; } for(i=0;i<=101;i++) { if(a[i]==max) c++; } printf("Case #%d:\n",t); if(max*c==k&&c!=1) printf("Bad Mushroom"); else { for(i=100;i>=0;i--) { if(a[i]==max) { if(sign==0) { printf("%d", 10000-i*i); sign=1; } else printf(" %d",10000-i*i); } } } printf("\n"); } } return 0; }