清北学堂 对刚

3

 

/*同样是模拟 约瑟夫环的问题 */
#include<cstdio>
#include<iostream>
int const MAXN=100005;
using namespace std;
struct type
{
    int from,to,q;
}k,num[MAXN];
int n,t,cnt;
int main ()
{
    freopen("resist.in","r",stdin);
    freopen("resist.out","w",stdout);
    scanf("%d%d",&n,&t);
    for (int i=1;i<=n;i++)
    {
        if (i==1)
        {
            num[i].from=n;
            num[i].to=i+1;
        }
        else 
            if (i==n)
            {
                num[i].from=n-1;
                num[i].to=1;
            }
            else 
            {
                num[i].from=i-1;
                num[i].to=i+1;
            }
    }
    int x=1;
    while (num[x].from!=x&&num[x].to!=x)
    {
        cnt++;
        if (cnt==t)
        {
            num[num[x].from].to=num[x].to;
            num[num[x].to].from=num[x].from;
            cnt=0;
        }
        x=num[x].to;
    }
    printf("%d",x);
    fclose(stdin);
    fclose(stdout);
    return 0;
}

 

posted @ 2016-10-05 21:13  球痞丶小七  阅读(131)  评论(0编辑  收藏  举报