博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3517 And Then There Was One
阅读量:4604 次
发布时间:2019-06-09

本文共 504 字,大约阅读时间需要 1 分钟。

#include<stdio.h>

#include<string.h>
#include<stdlib.h>
int num[10008];//n个人的编号
int copy[10008];
int n,k,m;
int f(int n)
{
    if(n==1)
    {
        return 0;
    }
    return (f(n-1)+k)%n;
}
int main()
{
    while(scanf("%d %d %d",&n,&k,&m),n||k||m)
    {
        int i;
        for(i=0;i<n;i++)
        {
            num[i]=i+1;
            copy[i]=num[i];
        }
        int np=0;
        for(i=m;i<n;i++)
        {
            num[np++]=copy[i];
        }
        for(i=0;i<m-1;i++)
        {
            num[np++]=copy[i];
        }
        n=np;//n个人,k循环的约瑟夫问题
        printf("%d\n",num[f(n)]);
    }
    return 0;
}

转载于:https://www.cnblogs.com/willzhang/archive/2012/07/12/2587405.html

你可能感兴趣的文章
JavaScript 操作 Cookie
查看>>
codeforce 605B. Lazy Student
查看>>
nginx默认的配置文件详解
查看>>
编程为什么有趣
查看>>
CentOS 6.8 安装vlc
查看>>
semantic parsing 入门
查看>>
Windows Phone 9再见了!
查看>>
爬虫大作业
查看>>
大数除法
查看>>
mysql优化
查看>>
[ Python - 15 ] win7安装paramiko问题总汇
查看>>
Containerpilot 配置文件 之 Telemetry
查看>>
vue项目中使用百度地图的方法
查看>>
[LeetCode]Merge k Sorted Lists
查看>>
设计模式六大原则(5):迪米特法则
查看>>
BZOJ 2901: 矩阵求和
查看>>
c#设置button透明
查看>>
OpenStack控制节点上搭建Q版glance服务(step4)
查看>>
matplotlib 刻度,坐标轴不可见
查看>>
poj1631 Bridging signals
查看>>