约瑟夫

传送门:https://www.luogu.org/problemnew/show/P1145

#include<cstdio>
using namespace std;
int cs;
int main()
{
    int k;
    scanf("%d",&k);
    int flag = 1,m = k;
    while(flag)
    {
        m++;//m至少为k+1
        cs = 0;
        for(int i = 0;i < k;i++)
        {
            cs = (cs + m - 1) % (2 * k - i);//(2k-i)为剩余人数,cs为下一次出列之人编号 
            if(cs < k) break; 
            if(i == k-1) flag = 0;
        } 
    }
    printf("%d\n",m);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/peppa/p/9878283.html