# 14268: 【原4268】助教吃火锅

### 题目描述

author: Lei Zheng 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4268

3 2

3

## ligongzzz's solution

``````#include <iostream>
#include <vector>
using namespace std;

int f(int n, int m) {
if (n == 1)
return 0;
return (f(n - 1, m) + m) % n;
}

int main() {
int n, m;
cin >> n >> m;

cout << f(n, m) + 1;

return 0;
}
``````

## victrid's solution

``````#include <iostream>
using namespace std;
int next(bool table[], int total, int start, int step);
int main()
{
int N;
int M;
int start = 0;
cin >> N >> M;
bool *table = new bool[N];
for (int n = 0; n < N; n++)
table[n] = true;
start = 0;
for (int i = 1; i <= N; i++)
{
start = next(table, N, start, M);
table[start] = false;
}
cout << start + 1;
return 0;
}
int next(bool table[], int total, int start, int step)
{
while (step != 0)
{
if (table[start])
step--;
if (step == 0)
return start;
++start;
if (start == total)
start = 0;
}
}
``````

## Zsi-r's solution

``````#include <iostream>

using namespace std;

//single

{
private:
struct node
{
int data;
node *next;

node(const int &x, node *N=NULL){
data = x; next = N;
}
node ():next(NULL){};
~node(){};
};

int currentLength;

node *move(int i)const;

public:

int length()const {return currentLength;}
void insert(int i,int x);
int eat(int N, int M);
};

{
while(i-->=0)p = p->next;
return p;
}

{
currentLength = 0;
}

{
node *pos;

pos = move(i -1 );
pos->next=new node(x,pos->next);
++currentLength;
}

{
int length = N;

tmp = move(N - 1);

node *q = tmp ;

while(length!=1)
{
if (M > 1)
{
for (int i = 0; i < M-1;i++)
{
q = p;
p = p->next;
}
}
q->next = p->next;
delete p;
length--;
p = q->next;
}
return p->data;
}

int main()
{
int N, M;
cin >> N >> M;