码迷,mamicode.com
首页 > 编程语言 > 详细

【水?排序】10231 - 众数

时间:2014-10-25 22:38:41      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   for   strong   

【水·排序】10231 - 众数

Time Limit: 1000MS
Memory Limit: 32768KB

本题由南山鲍安其原创!在此感谢!


modes
【题目描述】
    在统计学中,将某个随机变量在实验中频数最高的取值称为“众数”。
    例如在数据{1,1,2,3,4,5}中,众数为1。
    需要注意的是,假如一组取值中有两个或两个以上取值的频数相同且最多,则他们都是众数。
    例如{1,1,2,2,3,4,5}中的众数为1、2。
    现在给你一组数据,请你输出这组数据的众数,以及众数的频数。
    为了免去没有众数的情况,我们将保证不是所有取值的频数都相同。

【输入格式】
    第一行,一个数N,表示数据的总数;
    第二行,N个整数Ci,为所有的取值。

【输出格式】
    第一行两个整数M、P,用空格分开,表示众数的个数及频数;
    以下M行,以升序输出各个众数。

【样例输入】
7
5 4 3 2 2 1 1

【样例输出】
2 2
1
2

【数据规模】
    对于30%的数据,保证N<=3,000
    对于100%的数据,保证N<=100,000,0<=Ci<MaxLongint。

Source
noip

 1 # include<stdio.h>
 2 # include<cstring>
 3 # include<iostream>
 4 # include<algorithm>
 5 using namespace std;
 6 const int maxn=200000+10;
 7 int num[maxn],dp[maxn][2];
 8 int main(){
 9     int n,cur=0,temp=-1,Max=-1,tot=0;cin>>n;
10     for(int i=1;i<=n;i++)cin>>num[i];
11     sort(num+1,num+n+1);
12     for(int i=1;i<=n;i++)
13     if(num[i]!=temp){dp[++cur][0]=num[i];dp[cur][1]=1;temp=num[i];}
14     else dp[cur][1]++;
15     for(int i=1;i<=cur;i++)Max=max(Max,dp[i][1]);
16     for(int i=1;i<=cur;i++)if(dp[i][1]==Max)tot++;
17     printf("%d %d\n",tot,Max);
18     for(int i=1;i<=cur;i++)if(dp[i][1]==Max)printf("%d\n",dp[i][0]);
19     return 0;
20 }

 

【水?排序】10231 - 众数

标签:des   style   blog   http   color   io   os   for   strong   

原文地址:http://www.cnblogs.com/zoniony/p/4050909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!