题解
2024-07-16 15:09:46
发布于:广东
11阅读
0回复
0点赞
或许可用数组来做静态链表
方式如下:
#include<bits/stdc++.h>
using namespace std;
const int N =1e6;
int a[N+1];
int main(){
int n,x;
cin>>n>>x;
for(int i=1;i<=n;i++) //里面的数据是下个的下标
a[i]=i+1;
a[n]=1;
int prev=1,now=1;
while((n--)>1){
for(int i=1;i<x;i++){
prev=now;
now=a[prev];
}
a[prev]=a[now];
now=a[prev];
}
cout<<now-1; //because 我的下标从1开始
return 0;
}
这里空空如也
有帮助,赞一个