http://acm.hdu.edu.cn/showproblem.php?pid=5038
就是求个众数 这个范围小 所以一个数组存是否存在的状态即可了
可是这句话真恶心 If not all the value are the same but the frequencies of them are the same, there is no mode.
事实上应该是这个意思:
当频率最高的有多个的时候。
假设 全部的grade出现的频率都是相等的,那么是没有mode的
否则依照升序
当然假设频率最高的有一个。还是有mode的
//#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #include <map> #include <set> #include <queue> using namespace std; #define ls(rt) rt*2 #define rs(rt) rt*2+1 #define ll long long #define ull unsigned long long #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define CL(a,b) memset(a,b,sizeof(a)) #define IN(s) freopen(s,"r",stdin) #define OUT(s) freopen(s,"w",stdout) const ll ll_INF = ((ull)(-1))>>1; const double EPS = 1e-8; const double pi = acos(-1.0); const int INF = 100000000; const int MAXN = 1e6+200; int g[MAXN]; int a[MAXN],n,vis[MAXN]; int cnt[MAXN]; int out[MAXN]; //map<int,int>cnt; int main() { //IN("hdu5038.txt"); int ncase,n; scanf("%d",&ncase); for(int ic=1;ic<=ncase;ic++) { CL(cnt,0); CL(vis,0); scanf("%d",&n); int mmax=0;//,mm=0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); g[i]=10000 - (100-a[i])*(100-a[i]); cnt[g[i]]++; //vis[a[i]]=1; mmax=max(mmax,cnt[g[i]]); // mm=max(mm,g[i]); } int flag=0; int cc=0; for(int i=0;i<n;i++) { if(mmax == cnt[g[i]] && !vis[g[i]]) { out[cc++]=g[i]; vis[g[i]]=1; } if(mmax != cnt[g[i]]) { flag=1; } } printf("Case #%d: ",ic); if(flag==0 && cc>1)puts("Bad Mushroom"); else { sort(out,out+cc); printf("%d",out[0]); int last=out[0]; for(int i=1;i<cc;i++) { if(out[i]!=last) { last=out[i]; printf(" %d",out[i]); } } putchar(' '); } } return 0; }