洛谷P2397 yyy loves Maths VI (mode) 摩尔投票
求众数的一种方法
不需要内存,排序
每次记录上次加的值以及个数,相等个数+1,不相等就-1
因为众数大于一半 最坏的情况也就是拿一个众数取走一个非众数
最后的结果肯定就是众数
//#pragma comment (linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<time.h>
#include<bitset>#define myself i,l,r
#define lson i<<1
#define rson i<<1|1
#define Lson i<<1,l,mid
#define Rson i<<1|1,mid+1,r
#define half (l+r)/2
#define lowbit(x) x&(-x)
#define min4(a, b, c, d) min(min(a,b),min(c,d))
#define min3(x, y, z) min(min(x,y),z)
#define max3(x, y, z) max(max(x,y),z)
#define max4(a, b, c, d) max(max(a,b),max(c,d))
#define pii make_pair
#define pr pair<int,int>
typedef unsigned long long ull;
typedef long long ll;
const int inff = 0x3f3f3f3f;
const long long inFF = 9223372036854775807;
const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
const int mdir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 1, -1, -1, -1};
const double eps = 1e-10;
const double PI = acos(-1.0);
const double E = 2.718281828459;
using namespace std;
const int mod=1e9+7;
int num,cnt;
int main()
{int n,x;cnt=0;cin>>n;while(n--){cin>>x;if(cnt==0) cnt++,num=x;else{if(num!=x) cnt--;else cnt++;}}cout<<num<<endl;
}
洛谷P2397 yyy loves Maths VI (mode) 摩尔投票相关推荐
- [洛谷2397]yyy loves Maths VI
题目背景 自动上次redbag用加法好好的刁难过了yyy同学以后,yyy十分愤怒.他还击给了redbag一题,但是这题他惊讶的发现自己居然也不会,所以只好找你 题目描述 他让redbag找众数 他还特 ...
- 洛谷——P2393 yyy loves Maths II
P2393 yyy loves Maths II 题目背景 上次蒟蒻 redbag 可把 yyy 气坏了,yyy 说他只是小学生,蒟蒻 redbag 这次不坑他了. 题目描述 redbag 给了 yy ...
- 洛谷P2396 yyy loves Maths VII【状压dp】
题目:https://www.luogu.org/problemnew/show/P2396 题意:有n个数,每次选择一个表示走$a[i]$步,每个数只能选一次. 最多有两个厄运数字,如果走到了厄运数 ...
- 「洛谷P2397」 yyy loves Maths VI (mode) 解题报告
P2397 yyy loves Maths VI (mode) 题目背景 自动上次redbag用加法好好的刁难过了yyy同学以后,yyy十分愤怒.他还击给了redbag一题,但是这题他惊讶的发现自己居 ...
- 洛谷乐多赛 yyy loves Maths VI (mode)
题目描述 他让redbag找众数 他还特意表示,这个众数出现次数超过了一半 一共n个数,而且保证有 n<=2000000 而且每个数<2^31-1 时间限制 1s 空间限制 3.5M(你没 ...
- P2393 yyy loves Maths II
P2393 yyy loves Maths II # yyy loves Maths II ## 题目背景 上次蒟蒻 redbag 可把 yyy 气坏了,yyy 说他只是小学生,蒟蒻 redbag 这 ...
- 洛谷 4828 Nagisa loves Tomoya 题解
博客观赏效果更佳](https://lightninguz2.github.io/2019/11/02/洛谷-4828-Nagisa-loves-Tomoya-题解/) 题意简述 给定一个序列aaa, ...
- P2396 yyy loves Maths VII 状压dp 变态卡常
很容易想到dp,但是1<<24都有1600w的复杂度,要是普通做法肯定T掉 共有maxs=(1<<n)-1种情况 首先f[ ]记录某种情况的方案数,dis[ ]记录某种情况的步 ...
- 洛谷P4831 Scarlet loves WenHuaKe
这道题告诉我们推式子的时候头要够铁. 题意 问一个\(n\times m\)的棋盘,摆上\(n\times 2\)个中国象棋的炮使其两两不能攻击的方案数,对\(998244353\)取模. \((n\ ...
最新文章
- What-If 工具:无需写代码,即可测试机器学习模型
- 一文盘点深度学习13个常见问题(附详细解答amp;学习资源)
- 74HC595的使用
- 苏宁大调整中的三个关键
- python用于数据分析的案例_Python数据分析经典案例
- 在Ubuntu中实验环境配置《操作系统原理与实践-李治军》
- 高手请进关于RAID和热备
- mysql 语句中的national 、 comment
- GIT命令行的一些基本操作
- 知名大企业的愿景和使命
- RecyclerView 实现横向滚动效果
- java Base64编解码
- 高职单招面试自我介绍稿子计算机专业,单招面试自我介绍稿子范文
- 随手记 web服务器
- 帅某---考研---空间直线绕坐标轴旋转、二次曲面方程
- 整理了MariaDB和MySQL数据库历年发布版本和对应关系,方便记忆命令。
- python中函数返回值为func 和func() 的区别
- 工具论-科学是实用工具
- java常用的接口和类的说明,Java程序连接数据库的常用的类和接口介绍
- WarGame bandit