bzoj 2456: mode(找众数)
来源:互联网 发布:企业数据备份管理制度 编辑:程序博客网 时间:2024/06/06 02:37
2456: mode
Time Limit: 1 Sec Memory Limit: 1 MBSubmit: 3607 Solved: 1515
[Submit][Status][Discuss]
Description
给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数。
Input
第1行一个正整数n。
第2行n个正整数用空格隔开。
Output
一行一个正整数表示那个众数。
Sample Input
5
3 2 3 1 3
3 2 3 1 3
Sample Output
3
HINT
100%的数据,n<=500000,数列中每个数<=maxlongint。
思路:对两两不相等的数进行抵消,则最后剩下的数则是该众数! 用num记录当前抵消后剩下的数,当num=0的时候把该数变为tmp,不等则cnt--,相等则cnt++#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ int tot = 1 , n , num , tem; scanf("%d%d",&n,&num); for(int i = 2 ; i <= n ; i++) { scanf("%d",&tem); if(tot == 0) { tot = 1; num = tem; continue; } if(num == tem) tot++; else tot--; } printf("%d\n",num); return 0;}
0 0
- bzoj 2456: mode(找众数)
- BZOJ 2456 mode(找众数)
- 【bzoj 2456】 mode 众数
- BZOJ 2456 mode (求众数)
- bzoj 2456: mode 【思维 求众数】
- BZOJ 2456: mode(巧取众数)
- [BZOJ 2456] mode 常数时间求众数/队列压缩
- 众数(Mode)
- bzoj 2456 mode 题解
- BZOJ 2456: mode
- bzoj 2456: mode
- bzoj 2456 mode
- bzoj--2456--mode(规律)
- BZOJ 2456: mode【思维】
- BZOJ 2456: mode【妙脆角】
- BZOJ 2456, Mode
- 【BZOJ】2456 mode 模拟
- bzoj 2456 mode
- java 实现 mysql 数据库导出与导入(适合linux和windows)
- Android Gradle实用技巧——多渠道打包
- 媒体查询-手机尺寸参考
- 解决MySQL ERROR 1130 (HY000): Host 'XXXX' is not allowed to connect to this MySQL server
- vagrant 环境配置以及常用命令
- bzoj 2456: mode(找众数)
- 112. Path Sum
- redis的选择和定位
- 数组中的逆序对
- Test.java
- layer的layer.alert()自定义方法
- 防止点浏览器返回按钮,返回上一页的JS方法
- 5不可思议的旅游目的地参观
- oscache介绍