头君在和他的朋友们一起玩一个游戏。由于蒜头君的机智,这个游戏由蒜头君担任裁判。
首先,蒜头君会给他们一人一个编号,并且每个人的编号都不相同。接下来的每一回合,蒜头君会给一个数,编号不超过它的最大编号的人要报出自己的编号。如果没有人的编号比蒜头君给出的数要小,那么编号最小的人要报出自己的编号。每个人可以重复报号。
蒜头君会按照一个列表顺次报出每个回合的数,他的朋友们想知道每回合报出的编号应该是多少。你能帮帮他们吗?
第一行输入两个整数,表示人数和第几个出队
输出队中只有一个的编号
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
using namespace std;
queue<int> q;
int num[2000] = {0};
int main()
{
int n,m;
cin>>n>>m;
int res = n , cnt = 1;
for(int i=1; i<=n; i++)
{
num[i] = i;
}
while(res !=1 )
{
for(int i=1; i<=n; i++)
{
if(num[i] !=0 && cnt %m ==0 )
{
cnt = 1;
res--;
num[i] = 0;
if(res == 1)
break;
continue;
}
if(num[i] !=0 && cnt%m !=0)
{
cnt++;
}
}
}
// cout<<"RES+"<<res<<endl;
for(int i=1; i<=n; i++)
{
if(num[i] != 0 )
cout<<i<<endl;
}
return 0;
}