[BZOJ2456/ZOJ2132]mode/The Most Frequent Number
生活随笔
收集整理的這篇文章主要介紹了
[BZOJ2456/ZOJ2132]mode/The Most Frequent Number
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接:
BZOJ2456
ZOJ2132
日常鍛煉思維(雖然這題很簡單就是了)
因?yàn)楸姅?shù)個(gè)數(shù)超過\(\frac n2\),那么若數(shù)列中有兩個(gè)數(shù)不相同就消去,最后眾數(shù)一定可以抵消掉所有其他數(shù)。
然后模擬即可。
#include <cstdio>int n,a,c,x; //a 當(dāng)前數(shù),c 當(dāng)前數(shù)個(gè)數(shù)int main() {scanf("%d",&n);while(n--){scanf("%d",&x);if(!c)a=x,c=1;//新數(shù)else if(a==x)++c;//相同,個(gè)數(shù)+1else --c;//不相同,抵消}printf("%d\n",a);return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/LanrTabe/p/10211612.html
總結(jié)
以上是生活随笔為你收集整理的[BZOJ2456/ZOJ2132]mode/The Most Frequent Number的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Crontab和sudo中无法使用Ten
- 下一篇: 金额大写转换函数