BZOJ 2456
Description
给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数。
Input
第1行一个正整数n。
第2行n个正整数用空格隔开。
Output
一行一个正整数表示那个众数。
Sample Input
3 2 3 1 3
Sample Output
HINT
100%的数据,n<=500000,数列中每个数<=maxlongint。
zju2132 The Most Frequent Number
Source

#include<cstdio>
using namespace std;
int n,t,cnt;
int main(){
scanf("%d",&n);
for(int i=,x;i<=n;i++){
scanf("%d",&x);
if(x==t) cnt++;
else{
cnt--;
if(cnt<=) cnt=,t=x;
}
}
printf("%d",t);
return ;
}
BZOJ 2456的更多相关文章
- BZOJ 2456 杂题 卡内存
2456: mode Time Limit: 1 Sec Memory Limit: 1 MBSubmit: 3702 Solved: 1551[Submit][Status][Discuss] ...
- BZOJ 2456: mode 水题
2456: mode Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php? ...
- Bzoj 2456: mode 数论,众数
2456: mode Time Limit: 1 Sec Memory Limit: 1 MBSubmit: 2843 Solved: 1202[Submit][Status][Discuss] ...
- BZOJ 2456: mode(新生必做的水题)
2456: mode Time Limit: 1 Sec Memory Limit: 1 MB Submit: 4868 Solved: 2039 [Submit][Status][Discuss ...
- [BZOJ 2456]Mode(神奇的抵销)
题意:求一串数的众数(保证次数的出现次数超过一半),n<=500000 很简单是不是……快拍一下不就行了吗,不超时呢=W=,不过……尼玛空间只有1M…… 于是此题就成了神题(理解成智商题= =本 ...
- bzoj 2456: mode
#include<cstdio> #include<algorithm> using namespace std; int n,t,sum; int main() { scan ...
- BZOJ 2456 mod
又见神TM卡内存题.这道题是要求众数. 怎么求呢?首先这道题要求众数的个数大于一半,因此我们读入一个,如果和rec不一样就cnt--.如果cnt<=0了,则更新rec为当前数. 听起来很有问题? ...
- BZOJ 2456: mode(乱搞)
挺神奇的一道题,被1M内存坑了好久= =,这道题得记录当前众数以及众数与其他数的差,如果现在读入的这个数与众数相等,就加1,否则减一,如果差为0就替代掉他,可以证明如果众数存在的话这样一定能找出来 C ...
- BZOJ.2456.mode(绝对众数)
题目链接 \(Description\) 限制空间(只能保留两个变量),求给定n个数中出现次数超过\(\frac{n}{2}\)的数. \(Solution\) 维护两个变量,\(now\)和\(cn ...
随机推荐
- easyui combobox筛选(拼音)
1.combobox本身的筛选 $('#cc').combobox({ filter: function(q, row){ var opts = $(this).combobox('options') ...
- Oracle主键自增的实现
create sequence seq_字段名_表名 minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by ...
- 用Java实现菱形的打印输出
import java.util.Scanner; public class dengyao2 { public dengyao2() { super(); } public static void ...
- HTML第八天笔记
第一个知识点是关于伪类的,代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- Object Pascal对象模型中构造函数之研究
http://www.delphi2007.net/delphiblog/html/delphi_2004511950333715.html 前言 近期,一直在使用 C++ 与 Object Pasc ...
- TCommThread -- 在delphi线程中实现消息循环
http://www.techques.com/question/1-4073197/How-do-I-send-and-handle-message-between-TService-parent- ...
- 字符集乱码问题:ISO-8859-1和GBK
问题,引用百度知道的问题吧: http://zhidao.baidu.com/question/51342167.html?qbl=relate_question_0&word=%C3%84% ...
- [AngularJS] Adding custom methods to angular.module
There are situations where you might want to add additional methods toangular.module. This is easy t ...
- 清除SQL Server 2008中登陆时的历史记录
win7 在地址栏直接输入下面路径,删除SqlStudio.bin文件%AppData%\Microsoft\Microsoft SQL Server\100\Tools\Shell
- javascript实现单例模式
1.简单实现单例模式: var singleTon = function(){ var _pria = 'private value'; var show_pria = function(){ con ...