ZOJ 2132 the most frequent number
来源:互联网 发布:阿里云幕布邮寄要多久 编辑:程序博客网 时间:2024/06/03 13:53
Description
Seven (actually six) problems may be somewhat few for a contest. But I am really unable to devise another problem related to Fantasy Game Series. So I make up an very easy problem as the closing problem for this contest.
Given a sequence of numbers A, for a number X if it has the most instances (elements of the same value as X) in A, then X is called one of the most frequent numbers of A. Now a sequence of numbers A of length L is given, and it is assumed that there is a number X which has more than L / 2 instances in A. Apparently X is the only one most frequent number of A. Could you find out X with a very limited memory?
Input
Input contains multiple test cases. Each test case there is one line, which starts with a number L (1 <= L <= 250000), followed by L numbers (-2^31 ~ 2^31-1). Adjacent numbers is separated by a blank space.
Output
There is one line for each test case, which is the only one most frequent number X.
Sample Input
5 2 1 2 3 28 3 3 4 4 4 4 3 4
Sample Output
24
找出数组中超过半数的那个数,限制了内存大小,可以用map或链表过,但其实有更简单的办法。
#include<iostream> #include<algorithm>#include<cstdio>#include<string>using namespace std;int n, x, a, b;int main(){while (~scanf("%d", &n)){for (int i = a = b = 0; i < n; i++){scanf("%d", &x);if (b == 0) { a = x; b = 1; }else if (a == x) b++; else b--;}printf("%d\n", a);}return 0;}
- zoj 2132 The Most Frequent Number
- ZOJ 2132 The Most Frequent Number
- ZOJ 2132 the most frequent number
- ZOJ 2132 The Most Frequent Number 贪心
- zoj 2132.The Most Frequent Number
- The Most Frequent Number
- BIT1006 The most frequent number
- BIT 1006 The most frequent number
- bit 1006 The most frequent number
- 寒假练习 1006 The most frequent number
- BZOJ2456 Mode & zju2132 The Most Frequent Number
- 2013寒假练习 1006:The most frequent number
- BIT寒假练习-2013__1006:The most frequent number
- BZOJ2456 Mode & zju2132 The Most Frequent Number(众数性质)
- checkio the most frequent weekdays
- Python checkio "The Most Frequent Weekdays"解决方案
- 反素数应用 ZOJ 2562 More Divisors + Timus OJ 1748. The Most Complex Number
- ZOJ-2132-The MostFrequent Number题解
- Illegal overloaded getter method with ambiguous type for property
- 基于ngx_lua模块的waf开发实践
- 欢迎使用CSDN-markdown编辑器
- 概率论--随机事件及运算
- 一道淘汰85%面试者的百度开发者面试题
- ZOJ 2132 the most frequent number
- Windows下OpenLDAP的安装及使用(一)
- 仿微信/支付宝的密码输入框效果 android
- 训练深度神经网络的时候需要注意的一些小技巧
- 125Valid Palindrome
- Android官方培训课程中文版(v0.9.1)
- 国内外优秀呼叫中心系统简介
- uva 620 递归(DP)
- 交换排序-冒泡排序