Hdu 1443 Joseph
Joseph
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1512 Accepted Submission(s):
948
who are not familiar with the original problem: from among n people, numbered 1,
2, . . ., n, standing in circle every mth is going to be executed and only the
life of the last remaining person will be saved. Joseph was smart enough to
choose the position of the last remaining person, thus saving his life to give
us the message about the incident. For example when n = 6 and m = 5 then the
people will be executed in the order 5, 4, 6, 2, 3 and 1 will be
saved.
Suppose that there are k good guys and k bad guys. In the circle
the first k are good guys and the last k bad guys. You have to determine such
minimal m that all the bad guys will be executed before the first good guy.
The last line in the input file contains 0. You can suppose that 0 < k <
14.
containing m corresponding to k in the input file.
#include <iostream>
using namespace std;
int Joseph(int k,int m)
{
int len = *k;
int i;
int n = ; //n是要出去的位置,起始位置初始化为1
for (i=;i<=k;i++)
{
n = (n+m-)%len; //第i次出去的人
if(n==) //最后一个人出去
n = len;
if(n<=k) //n小于或等于k时候,返回false
return false;
len--; //出去一个人,则长度减1
}
return true;
} int main()
{
int a[];
int i,j;
for (i=;i<;i++)
for(j=i+;;j++)
if (Joseph(i,j))
{
a[i] = j;
break;
}
int n;
while(cin>>n && n)
cout<<a[n]<<endl;
return ;
}
Hdu 1443 Joseph的更多相关文章
- poj 1012 & hdu 1443 Joseph(约瑟夫环变形)
题目链接: POJ 1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http:// ...
- hdu 1443 Joseph (约瑟夫环)
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1443 Joseph【约瑟夫环】
题目 题意:一共有2k个人,分别为k个好人和k个坏人,现在我们需要每隔m个人把坏人挑出来,但是条件是最后一个坏人挑出来前不能有好人被挑出来..问最小的m是多少 约瑟夫环问题,通常解决这类问题时我们把编 ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- hdu Joseph
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; ]; ...
- HDU 5860 Death Sequence(死亡序列)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5860 Death Sequence(递推)
HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- SDCycleScrollView 滚动视图的使用(广告)
github库链接https://github.com/gsdios/SDCycleScrollView 无限循环自动图片轮播器(一步设置即可使用) // 网络加载图片的轮播器 cycleScroll ...
- NHibernate 基本配置 (第一篇)
使用NHibernate最重要的一步就是配置,如果连NHibernate都还没有跑的起来,谈何学习.今天就来详解一下NHibernate的配置. 一.NHibernate基本配置 NHibernate ...
- [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离
18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...
- [zt]java synchronized详解
作者:GangWang 出处:http://www.cnblogs.com/GnagWang/ 记下来,很重要. Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多 ...
- HTML - 毛玻璃 滤镜 模糊
css 秘密花园 http://dabblet.com/gist/d9f243ddd7dbffa341a4 场景,背景图片 + 毛玻璃遮盖 原理:利用background的cover特性,将毛玻璃的区 ...
- mysql分区及实例演示
一.为什么要分区? 需求:大数据.解决方案:分而治之,更细一点即为.将大表和大索引分为一个更小的操作单元 在mysql中,分区允许将表.索引和索引编排表细分为更小的单元.分区后,每个分区有自己单独的名 ...
- php课程---练习(联系人信息表)
做一个联系人表,实现增删改功能 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...
- Spinner的深入学习
简介: spinner是一个列表选择框,会在用户选择后,展示一个列表供用户进行选择.Spinner是ViewGroup的间接子类,它和其他的Android控件一样,数据需要使用Adapter进行封装. ...
- Bootstrap:表格和栅格分页
拼接table请将以下代码直接运行:换下 bootstrap.css jquery-1.12.3.min.js bootstrap-paginator.min.js" <!DOCT ...
- CSS权威指南 - 内边距 边框 和 外边距
九十年代的完全用表格布局,简单的段落边框都需要用表格.CSS让布局更方便. 基本元素框 basic element boxes 如同第七章基本视觉格式化那一章讲到,每个文档元素会生成一个元素框,这个框 ...