题目链接:
瞎扯
这是今天考的模拟赛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