2199. [HZOI 2016] event vote, 2199 hzoi
★★Input file:hztp.in
Output file:hztp.out
Simple comparison
Time Limit: 0.5 s memory limit: 2 MB
[Description]
There are many and many people in the China-based shopping festival. n students are voting for one event. Now, more than half of the contestant's votes are received and their contestant numbers are requested (random contestant numbers)
[Input format]
The first line is an integer n.
The n integer Ni in the second row represents the contestant ID for the I student.
[Output format]
Number of more than half of contestants
[Example input]
10
5 1 2 5 5 2 3 5 5
[Sample output]
5
Tip]
In 100% of the data: n ≤ 300rmb, 1 ≤ Ni ≤ 300000000;
[Source]
Hzoid 2016
If the values are the same, the values are added. If the values are different, the values are subtracted.
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 }