竞赛
考级
法兰西玫瑰
#include <bits/stdc++.h> using namespace std; queue<int> que; long long n,k,temp,cnt=0; int main(){ cin>>n>>k; for (int i=0;i<n;i++){ cin>>temp; que.push(temp); } temp=que.front(); que.pop(); while (cnt<k){ if (temp>que.front()){ cnt++; que.push(que.front()); que.pop(); } else if (temp<que.front()){ cnt=0; que.push(temp); temp=que.front(); que.pop(); } } cout<<temp; }
Dr.无面人
bits/stdc++.h
懒得喷
yy
这道题太简单了\Huge 太简单了太简单了狗TM都会 上代码!↓\Huge 上代码!↓上代码!↓ ①:为什么q2的定义要放在里面? 因为p1是第一个,p1定义完后q.pop()了,p2成为队首,第一轮结束后可能产生新队首,所以要放在里面。 ②:这里可能想象力不好的就看不懂了,用样例1仔细列一下: ③:这里可能想象力不好的就看不懂了,用样例1仔细列一下: 懂了吗,懂了评论区扣1,不懂扣亽暨齑髻尐
qianqian
#include<bits/stdc++.h> using namespace std; int main(){ queue<long long> a; long long n,k,ans=0; cin>>n>>k; for(int i=0;i<n;i++){ long long x; cin>>x; a.push(x); } long long sum=0; long long win=a.front(); a.pop(); while(sum<k){ long long next=a.front(); a.pop(); if(win>next){ sum++; a.push(next); } else{ sum=1; win=next; } } cout<<win; return 0; }
师宇辰
北辞
陈炜涵
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=250005; ll n,k,ans,x; int q[N],top; int main(){ cin>>n>>k; for(int i=1;i<=n;i++){ cin>>x; q[top]=x;//入队 ans=max(x,ans); } if(k>=n-1){ cout<<ans; return 0; } int cnt=0,now=1,now2=2; while(cnt!=k){ if(q[now]>q[now2]){ q[top]=q[now2]; now2; cnt; }else{ q[top]=q[now]; now=now2; now2; cnt=1; } } cout<<q[now]; return 0; }
↯ 暗黑之龙™
juhan214
提交答案之后,这里将显示提交结果~