先写个链表版的,,,
dp版的以后再说
#include <queue>
#include <cstdlib>
#include <iostream>
#include <cstdio>
using namespace std;
struct node{
int num;
node *next;
node (){num=0;next=NULL;}
};
int fun(int m,int n){
node *pre,*head=new node;
head->num=1;
pre=head;
for(int i=2;i<=n;i++){
node *cur=new node;
cur->num=i;
pre->next=cur;
pre=cur;
}
pre->next=head;
node *cur=head;
node *p=head,*q=head;
//work
for (int j=0;cur->next!=cur;cur=cur->next){
j++;
if (j%m==0) pre->next=cur->next;
pre=cur;
}
return cur->num;
}
int main(){
int a,b;
cout<<"请输入人数,报号数"<<endl;
cin>>a>>b;
cout<<"最后的胜利者是:NO."<<fun(b,a)<<endl<<"lzl==sz"<<endl;
return 0;
}