HDU 5038 Grade

Source: Internet
Author: User

Problem-solving ideas: The most important thing is to read test instructions, If not all the value was the same but the frequencies of the them was the same, there is no mode. That's a crucial word.

A sentence. This means: If not all the values are the same, and their occurrences are the same, then there is no model. For example, 1 1 2 2 3 3, they are not all of the numbers are the same,

and 1 appeared 2 times, 2 appeared 2 times, 3 appeared 2 times, so this group of data is no model, the same, 1 2 3 4 5 is also no model, output bad Mushroom. But pay attention to special judgments,

For example, 1 1 1 1 1, all of its numbers are the same, it is a unique model.

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineINF 0x3f3f3f3fConst intMAXN =1000005;intHASH2[MAXN], NUM[MAXN], VIS[MAXN];intW[MAXN], S[MAXN];intMain () {intT, N, Kase =1; scanf ("%d", &t);  while(T--) {scanf ("%d", &N); memset (HASH2,0,sizeof(HASH2));  for(inti =0; I < n; i++) {scanf ("%d", &W[i]); S[i]=10000- ( --w[i]) * ( --W[i]); Hash2[s[i]]++;//the number of occurrences of each corresponding grade is marked with a hash. } printf ("Case #%d:\n", Kase + +); intOK =0;  for(inti =1; I < n; i++)        {            if(S[i]! = s[0])//determine if all the grade are the same. {OK=1;  Break; }        }        if(OK = =0)//If all the grade are the same, the output is direct. {printf ("%d\n", s[0]); Continue;//don't drop it.         }        intMAX1 =-inf;  for(inti =0; I < n; i++)        {            if(Hash2[s[i]] >=max1) {Max1= Hash2[s[i]];//Find out the maximum number of grade occurrences, can have more than one.             }        }        intCNT =0; intFlag =0; memset (Vis,0,sizeof(VIS));  for(inti =0; I < n; i++)        {            if(Hash2[s[i]] < MAX1) flag =1;//If there is a number that is not the same as the maximum number of occurrences, the//there must be an output.             if(Hash2[s[i]] = = Max1 &&!Vis[s[i]]) {Vis[s[i]]=1; Num[cnt+ +] = S[i];//The number of times the CNT record is the most frequent, and the NUM array to save the corresponding value.             }        }        if(!flag)//if the frequency of all occurrences is the same, there is no model. {printf ("Bad mushroom\n"); Continue; }        if(CNT = =1) printf ("%d\n", num[0]);//a direct output.         if(CNT >1) {sort (num, num+CNT);  for(inti =0; I < cnt-1; i + +) printf ("%d", Num[i]); printf ("%d\n", num[cnt-1]);//note the output format.         }    }    return 0;}
View Code

HDU 5038 Grade

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.