POJ 3517 And Then There Was One( 约瑟夫环模板 )
**链接:****传送门 **
题意:典型约瑟夫环问题
约瑟夫环模板题:n个人( 编号 1~n )在一个圆上,先去掉第m个人,然后从m+1开始报1,报到k的人退出,剩下的人继续从1开始报数,求最后剩的人编号
/*************************************************************************
> File Name: poj3517.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月10日 星期三 14时49分41秒
************************************************************************/
#include<cstdio>
using namespace std;
int Joseph(int n,int k,int m){
int d , s = 0;
for(int i = 2 ; i<= n ; i++) s = ( s + k ) % i;
k %= n;
if( k == 0 ) k = n;
d = ( s + 1 ) + ( m - k );
if( d >= 1 && d <= n ) return d;
else if( d < 1 ) return d + n;
else if( d > n ) return d % n;
}
int main(){
int n,k,m;
while(~scanf("%d%d%d",&n,&k,&m) , n||k||m ){
printf("%d\n",Joseph(n,k,m));
}
return 0;
}
POJ 3517 And Then There Was One( 约瑟夫环模板 )的更多相关文章
- Poj 3517 And Then There Was One(约瑟夫环变形)
简单说一下约瑟夫环:约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列:他的下一个人又从1开始报数,数到m的那个 ...
- poj 1012 & hdu 1443 Joseph(约瑟夫环变形)
题目链接: POJ 1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http:// ...
- (顺序表应用5.1.1)POJ 3750 小孩报数问题(基本的约瑟夫环问题:给出人数n,出发位置w,间隔数s)
/* * POJ_3750.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- poj 3517
题目链接 http://poj.org/problem?id=3517 题意 约瑟夫环 要求最后删掉的那个人是谁: 方法 理解递推公式就行了 考虑这样一组数据 k ...
- POJ 2359 Questions(约瑟夫环——数学解法)
题目链接: http://poj.org/problem?id=2359 题意描述: 输入一个字符串 按照下面的规则,如果剩下的最后一个字符是'?',输出"Yes",如果剩下的最后 ...
- Joseph POJ - 1012 约瑟夫环递推
题意:约瑟夫环 初始前k个人后k个人 问m等于多少的时候 后k个先出去 题解:因为前k个位置是不动的,所以只要考虑每次递推后的位置在不在前面k个就行 有递推式 ans[i]=(ans[i-1]+m ...
- POJ 2886 Who Gets the Most Candies?(线段树·约瑟夫环)
题意 n个人顺时针围成一圈玩约瑟夫游戏 每一个人手上有一个数val[i] 開始第k个人出队 若val[k] < 0 下一个出队的为在剩余的人中向右数 -val[k]个人 val[k ...
- C#实现约瑟夫环问题
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace orde ...
随机推荐
- 洛谷P1914 小书童——密码
题目背景 某蒟蒻迷上了"小书童",有一天登陆时忘记密码了(他没绑定邮箱or手机),于是便把问题抛给了神犇你. 题目描述 蒟蒻虽然忘记密码,但他还记得密码是由一串字母组成.且密码是由 ...
- windows 查看端口号被占用
1.netstat -ano 2.tasklist | findstr xxx 3.进程管理杀掉
- Linux 文件压缩
压缩工具 compress/uncompress:对应 .Z 结尾的压缩格式文件 压缩格式:gz.bz2.xz.zip.Z gzip 压缩文件并删除源文件(生成.gz的文件) gunzip 解 ...
- 2019-04-03 SQL Group By某列,预先对该列进行一个预处理,提炼出共有的信息,即关键字case when 列名什么条件 then 赋值 else 赋值 end as 新列名
select sum(发行金额) from( select PoolNameFormat,count(cast(ItemValue as decimal(19,4))) as 发行笔数,sum(cas ...
- 《你又怎么了我错了行了吧》【Alpha】Scrum meeting 2
第二天 日期:2019/6/15 前言: 第2次会议在9C-405召开 进行第一天工作的检查,开始第二天工作的安排和学习 1.1 今日完成任务情况以及明天任务安排 姓名 当前阶段任务 下一阶段任务 刘 ...
- Python中图像的缩放 resize()函数的应用
cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst 参数说明: src - 原图 dst - 目标图像.当参数ds ...
- [Tailwind] Extending Tailwind with Responsive Custom Utility Classes
You are able to extend the custom css with hover, focus, group-hover, responsive variants class in t ...
- HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)
题意:按要求输出.第一列是表示第几行.每行仅仅能有16个字节的字母,第二列是16进制的ASCII码.第三列大写和小写转换 思路:纯模拟,注意字母的十六进制是2位 #include <iostre ...
- WPF Prefix 'attach' does not map to a namespace.
这个是用附加属性时,一定要在属性前面加Path= Visibility="{Binding Path=PlacementTarget.(attach:CommonAttachedProper ...
- php利用反射真正实现多继承(非接口模拟)
昨天我在写PHP程序的时候,无意发现在PHP的::操作符非常强大,不仅仅是只用在访问parent,sel,静态成员属性.常量上面,其实他的功能强大了去了 . 这个符号在PHP中实际上叫做范围解析符,这 ...