题解
2023-07-07 20:58:56
发布于:江苏
52阅读
0回复
0点赞
#include<iostream>
using namespace std;
struct node{
int data;
node *pre,*next;
};
int main(){
node *head,*r,*p,*temp;
head=new node;
head->data=0;
head->pre=head;
head->next=head;
r=head;
int n,m;
cin>>n>>m;
for(int i=1;i<n;i++){
p=new node;
p->data=i;
p->next=r->next;
p->pre=r;
p->next->pre=p;
p->pre->next=p;
r=p;
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
head=head->next;
}
temp=head;
head->pre->next=head->next;
head->next->pre=head->pre;
head=head->next;
delete temp;
}
cout<<head->data;
return 0;
}
这里空空如也
有帮助,赞一个