bzoj2456

来源:互联网 发布:手写笔记软件 编辑:程序博客网 时间:2024/06/13 18:54


分析性质,如果两个数不同就相抵一次,相同就累加,因为出现了超过一半次,所以不会抵没了


#include<cstdio>#include<algorithm>using namespace std;int a,num,n;int main(){scanf("%d",&n);int x;for (int i=1;i<=n;i++){scanf("%d",&x);if (x==a) num++;else if (num==0) a=x,num=1;else num--;}printf("%d",a);return 0;}


0 0
原创粉丝点击