HDOJ 1029 Ignatius and the Princess IV 【math】

来源:互联网 发布:多益网络ipo结果 编辑:程序博客网 时间:2024/04/30 22:13

HDOJ 1029 Ignatius and the Princess IV 【math】

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1029


N是奇数,并且最后的special integer出现次数至少为 (N+1)/2
所以special integer出现的次数一定比其他所有数出现的总数还多
一点一点滴 耗死其他的数就可以鸟。。。


#include<cstdio>int N, num, cnt, ans;int main(){    while(~scanf("%d", &N)){        cnt = 0;        while(N--){            scanf("%d", &num);            if(cnt == 0){ // 刚开始或一个数已经被耗尽 开始计算新的数据                ans = num;                cnt++;            }            else{                if(ans == num) cnt++;                else cnt--;            }        }        printf("%d\n", ans);    }    return 0;}
0 0
原创粉丝点击