hdu 5038 Grade(アウトライン)

6941 ワード

タイトルリンク:[hdu 5038](http://acm.hdu.edu.cn/showproblem.php?pid=5038)テーマ記述:Graade
Time Limit:3000/1500 MS(Java/Others)Memory Limit:262144/262144 K(Java/Others)Total Submission(s):1330 Accepted Submission(s):567
Problem Description Ted is a employee of Always Cook Musshroom(ACM).His boss Matt gives him pack of mush rooms and ask him to grade each mush according to it s weight.Suppose the weigh of muth the ist's。
s=10000-(100-w)^2
What’s more,Ted also has to report the mode of the grade of the musshrooms.The mode is the value that appars most oten.Mode may not be unique.If not all the value the same the same.the frequene of the the the the the the the the the the the same.com。
Input The first line of the input contains an integer T,denoting the number of test cases.The n T T T test cases follow.
The first line of each test cases contains one integers N(1==N==10^6)、denoting the number of the mush room.
The second line contains N integers、denoting the weight of each musshrom.The weight is greater than 0、and less than 200.
Output For each test case,output 2 lineas.
The first line contains「Case((zhi x)」,where x is the case number(starting from 1)
The second line contains the mode of the grade of the given musshrooms.If there exists multiple modes,output the m in ascending order.If there existsのmode,output"Bad Musshroom"
Sample Input 3 6 100 100 100 100 99 101 100 100 99 99 99 99 101 6 100 100 98 99 99
Sample Output Case se〓1:10000 Case菗2:Bad Musshroom Case菗3:9999999 10000
Source 2014 ACM/ICPC Asia Regional Beijing Onlineは簡単に要約されています。この問題は上述の式を用いてすべてのMusshroomの等級を分けて、その中の全ての衆の数を探し出して、共通数が唯一であれば、直接出力すればいいです。唯一でなければ、昇順ですべての特別なものを出力します。非常に特殊な場合は、すべての可能性があるのは同じ頻度です。この場合は「Badmushoom」を出力します。しかし、この問題はすべての入力によってデータを格納する必要がありません。その地位によって直接に重さを処理して記憶と演算を行うことができます。より簡潔になり、コードの実現は以下の通りです。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;

int a[105];
int b[105];
int main()
{
    int t,n,k;
    int intg;
    scanf("%d",&t);
    for(int loop=1;loop<=t;loop++)
    {
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&intg);
            k=(int)abs(100-intg);
            a[k]++;//     ,            
        }
        int max=-99999999;
        int maxi=0;
        for(int i=0;i<=100;i++)//         
        {
            if(a[i]>max)
            {
                max=a[i];
                maxi=i;
            }
        }
        //cout<<"max="<<max<<endl;
        int j=0;
        int count=0;
        for(int i=0;i<=100;i++)
        {
            if(a[i]==max)
            {
                b[j++]=i;
                count++;
            }
        }
// for(int i=0;i<j;i++)
// {
// cout<<"b="<<b[i]<<" ";
// }
        printf("Case #%d:
"
,loop); if(count==1) { printf("%d
"
,10000-maxi*maxi); } else { if(count*max==n) { printf("Bad Mushroom
"
); } else { sort(b,b+j); for(int i=j-1;i>=0;i--) { if(i==0) printf("%d",10000-b[i]*b[i]); else printf("%d ",10000-b[i]*b[i]); }printf("
"
); } } } return 0; }
備考:小知識点:abs関数とfabs()関数について。abs()関数は、整数に絶対値(C++にヘッダファイルを追加するか、または)を取るために使用されます。fabs()関数は、小数点に絶対値(C++にヘッダファイルを追加するか、または)を取るために使用され、戻り値は実数形です。