Description
给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数。
数据范围: 100%的数据,n<=500000,数列中每个数<=maxlongint。
数据范围太大,于是在网上找的了一个比较神奇的找众数的方法:
因为题中规定了众数一定多于二分之一,所以可以每次搜到不同的数都抵消,最后剩下的一定是最多的那个;
代码:
/************************************************************** Problem: 2456 User: 1115825064 Language: C++ Result: Accepted Time:372 ms Memory:804 kb ****************************************************************/ #include<cstdio> using namespace std; int n,p; int x,a; int main() { scanf("%d",&n); while(n--) { scanf("%d",&a); if(!p) { p=1; x=a; } else { if(x==a) p++; else p--; } } printf("%d",x); return 0; }
2019年11月03日 09:52
敬启者:个人小网站希望大家多多支持 感谢您对我们热心的支持 f88tw┃华歌尔┃I appreciate your kind assistance.
http://mypaper.pchome.com.tw/f88tw/P1
http://mypaper.pchome.com.tw/f88tw/post/1379131888
http://mypaper.pchome.com.tw/f88tw/post/1370781143
f88tw
| 捡骨师| 佛经哥|墓园|禁忌|新竹|台北|桃园|苗栗|头份
2021年4月04日 22:12
敬启者:个人小网站希望大家多多支持 感谢您对我们热心的支持 f88tw┃华歌尔┃I appreciate your kind assistance. f88tw| 粗工| 粗工内容 | 粗工| 粗工内容 |墓园|捡骨流程|捡骨费用|捡骨时间|禁忌|捡骨颜色|捡骨师|新竹|时间|台北|桃园|苗栗|头份|https://mypaper.m.pchome.com.tw/f88tw
2021年11月15日 22:59
Precisely what is the perfect solution to remove all your after development messes all-around? From development dust via sheetrock for you to simple dirt which has been tracked though your own home, house cleanup service may help you restore order to your dwelling - and revel in the outcomes of your brand-new additions. They include the ones who discover how to remove airborne debris, debris, sawdust, and various other dirt that's collected after the development workers quit.