class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @param m int整型
* @return int整型
*/
int ysf(int n, int m) {
// write code here
bool que[n + 1]; // 记录此编号的人是否在队里
// 初始化所有人都在队里
for (int i = 0; i < n + 1; i++) {
que[i] = true;
}
int inQue = n; // 在队里的人数
int cnt = 0; // 当前报号
int pos = 0; // 当前位置
int end=0;
// 如果队里还有人
while (inQue > 0) {
if (cnt==m) {
que[pos]=false;
inQue--;
cnt=0;
end=pos;
// printf("%d ",pos);
}
pos++;
if (pos==n+1) {
pos=1;
}
if (que[pos]==true) {
cnt++;
}
}
return end;
}
};