活动投票

时间:2020-07-11 13:11:10   收藏:0   阅读:45

活动投票( 思维题\(\star?\))

Descrption

Input

Output

Sample Input

10
5 1 2 5 5 2 3 5 5 5

Sample Output

5

Hint

分析

Code

#include <bits/stdc++.h>
const int maxn=100+5,Inf=0x3f3f3f3f;

void Solve(){
    int cnt=0,ans,n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int x;scanf("%d",&x);
        if(cnt==0)//全抵消了那暂定为答案
            ans=x,cnt++;
        else
            if(x!=ans) --cnt;//不相同就抵消一对
            else ++cnt;//相同的个数加一
    }
    printf("%d\n",ans);
}
int main() {
    Solve();
    return 0;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!