2199. [HZOI 2016] 活动投票
生活随笔
收集整理的這篇文章主要介紹了
2199. [HZOI 2016] 活动投票
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
★★?? 輸入文件:hztp.in?? 輸出文件:hztp.out?? 簡(jiǎn)單對(duì)比
時(shí)間限制:0.5 s?? 內(nèi)存限制:2 MB
【題目描述】
衡中活動(dòng)很多,人也很多,一次活動(dòng)有n個(gè)學(xué)生參與投票,現(xiàn)已知一名參賽選手票數(shù)超過(guò)半數(shù),求其參賽號(hào)(參賽號(hào)隨機(jī))
【輸入格式】
第一行一個(gè)整數(shù)n
第二行n個(gè)整數(shù)Ni 代表第i個(gè)學(xué)生所投選手的參賽號(hào)
【輸出格式】
超過(guò)半數(shù)選手的參賽號(hào)
【樣例輸入】
10
5 1 2 5 5 2 3 5 5 5
【樣例輸出】
5
【提示】
100%的數(shù)據(jù)中:n ≤3000000,1 ≤ Ni ≤300000000;
【來(lái)源】
HZOI 2016
相同則加,不同則減
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<map> 5 using namespace std; 6 int n; 7 int maxn; 8 int num=1; 9 int p; 10 int main() 11 { 12 13 freopen("hztp.in","r",stdin); 14 freopen("hztp.out","w",stdout); 15 //ios::sync_with_stdio(false); 16 //scanf("%d",&n); 17 scanf("%d",&n); 18 for(int i=1;i<=n;i++) 19 { 20 scanf("%d",&p); 21 if(p!=maxn) 22 { 23 num--; 24 if(num<0) 25 { 26 maxn=p; 27 num=1; 28 } 29 } 30 else 31 num++; 32 } 33 cout<<maxn; 34 return 0; 35 }?
總結(jié)
以上是生活随笔為你收集整理的2199. [HZOI 2016] 活动投票的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: other-如何可以查看别人请求的输出结
- 下一篇: springboot-24-restTe