ickchen2

约瑟夫问题PKU3629

/*约瑟夫问题的直接模拟*/
#include<stdio.h>

#include<iostream>

#include<string>

#include<vector>

#include<map>

#include<queue>

#include<algorithm>

#define M 1000

using namespace std;

int cards[M];

int goodc[M];

int main()

{

    freopen("3629.txt","r",stdin);

    int tail=0,head=0;

    int play=0;

    int n,k,p;

    scanf("%d%d%d",&n,&k,&p);

    for(int i=0;i<k;i++)

    {

        cards[tail++]=i+1;

    }

    int len=0;

    while(head<=tail)

    {

        if(play==n-1)goodc[len++]=cards[head];

        head++;

        for(int i=0;i<p;i++)

        {

            cards[tail++]=cards[head++];

        }

        play=(play+1)%n;

    }

    sort(goodc,goodc+k/n);

    for(int i=0;i<k/n;i++)

    {

        printf("%d\n",goodc[i]);

    }

}

posted on 2008-10-03 11:26 神之子 阅读(161) 评论(0)  编辑 收藏 引用 所属分类: 数论


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜