宇宙超究极鸡心
2024-02-20 17:54:57
发布于:北京
#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
struct node {
int data;
int prev, next;
};
node point[N];
int head, tail, lp;
void print_lst() {
int step = head;
while (step) {
cout << point[step].data << ' ';
step = point[step].next;
}
}
void print_lst_re() {
int step = tail;
while (step) {
cout << point[step].data << " ";
step = point[step].prev;
}
}
void append_data(int x) {
lp ++;
if (tail == 0) {
head = tail = lp;
point[tail].data = x;
} else {
point[lp].data = x;
point[lp].next = point[tail].next;
point[lp].prev = tail;
point[tail].next = lp;
tail = lp;
}
}
void insert_node(int p, int d) {
lp ++;
point[lp].data = d;
point[lp].next = point[p].next;
point[lp].prev = p;
point[p].next = lp;
if (p == tail) tail = lp;
else { point[ point[lp].next ].prev = lp; }
}
void del_data(int d) {
int step = head;
if (step == 0) return ;
while (step) {
if (point[step].data == d) {
if (step == head) {
head = point[head].next;
if (head == 0) {
tail = 0;
} else {
point[head].prev = 0;
}
} else if (step == tail) {
tail = point[tail].prev;
if (tail == 0) {
head = 0;
} else {
point[tail].next = 0;
}
} else {
point[point[step].prev].next = point[step].next;
point[point[step].next].prev = point[step].prev;
}
break;
}
step = point[step].next;
}
}
int main () {
head = tail = 0;
int n,m,d=1;
cin>>n>>m;
for(int i=1;i<=n;i++)
append_data(i);
point[head].prev = tail;
point[tail].next = head;
int t=head,num=0;
while(n-1){
num++;
if(num==m){
point[point[t].prev].next = point[t].next;
point[point[t].next].prev = point[t].prev;
n--;
num=0;
d=-d;
}
if(d>0)
t = point[t].next;
else
t = point[t].prev;
}
printf("%d",point[t].data);
}
这里空空如也
有帮助,赞一个