题解
2024-06-08 11:34:38
发布于:江苏
20阅读
0回复
0点赞
#include<iostream>
using namespace std;
const int qmaxsize=1000010;
int q[1000010];
int head,tail;
void init(){
head=tail=0;
}
void push(int x){
tail=(tail+1)%qmaxsize;
q[tail]=x;
}
void pop(){
head=(head+1)%qmaxsize;
}
int front(){
return q[(head+1)%qmaxsize];
}
int back(){
return q[tail];
}
bool empty(){
return headtail;
}
int size(){
return (tail+qmaxsize-head)%qmaxsize;
}
void clear(){
head=tail;
}
bool full(){
return (tail+1)%qmaxsizehead;
}
int main(){
init();
int n,k;
cin>>n>>k;
for(int i=0;i<=n-1;i++){
push(i);
}
while(size()!=1){
for(int i=1;i<k;i++){
push(front());
pop();
}
pop();
}
cout<<front();
return 0;
}
这里空空如也
有帮助,赞一个