BZOJ2456-mode题解--一道有趣题

  • 题目链接:

    https://www.lydsy.com/JudgeOnline/problem.php?id=2456

  • 瞎扯

    这是今天考的模拟赛T2交互题的一个30分部分分,老师在讲题时提到了这题。考场上我比较菜并没有想出来

  • 分析:

    一个非常神奇美妙的做法,请大家直接看代码

    #include <iostream>
    #include <cstdio>
    template <class T>inline void read(T &x){ 
         x=0;int ne=0;char c;
         while(!isdigit(c=getchar()))ne=c=='-';
         x=c-48;
         while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
         x=ne?-x:x;
         return ;
    }
    int n,x,y=-0x7fffffff,tot=0;
    int main(){
        scanf("%d\n",&n);
        while(n--){
              read(x);
              if(x==y){
                   tot++;
              }
              else if(!tot){
                  y=x,tot=1;
              }
              else tot--;
        }
        printf("%d\n",y);
        return 0;
    }

转载于:https://www.cnblogs.com/Rye-Catcher/p/9271419.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值