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. ...
随机推荐
- IIS7.0+部署ARR负载均衡
安装: 1. 安装IIS(需要附带相关的健康检查,需要原始的那个默认站点) 2. 安装ARR相关的文件 3. 安装好之后,IIS里会出现有Server Farms的节点,直接创建服务器. 站点对 ...
- (转)KeyDown、KeyUp、KeyPress区别
Windows窗体通过引发键盘事件来处理键盘输入以响应Windows消息,大多数Windows窗体应用程序都通过处理键盘事件来以独占方式处理键盘输入. 1.按键的类型 Windows窗体将键盘输入标 ...
- 在springmvc中,获取Connection接口
ServletContext context = request.getSession().getServletContext();WebApplicationContext wac = WebApp ...
- Sortable Observable Collection in C#
Sorting outside the collection protected override void OnNavigatedTo(NavigationEventArgs e) { if (Se ...
- HDU 2577
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- echart 扩展地图不显示问题
今天写项目需要一个安徽地图,但echart自带的安徽地图还是老版的,仍有巢湖市,但客户要求不能有,只好重新找, 后发现ECharts 地图数据在线生成工具 :http://ecomfe.github. ...
- bug0
1,编码 之前做支付验证的时候,sdk的平台token串有的就是会有空格,折腾了很久,前后端对调好多次都没发现这个问题.结果有的平台验证通过,有的通不过. 仔细调试后发现不通过的url中参数串都是带有 ...
- css 多行溢出
<div style=" height: 38px; max-width: 180px; -webkit-box-orient: vertical; word-break: break ...
- 使用engine关键字指定该表使用哪个engine
建表及插入数据语句:mysql> create table salary(userid int,salary decimal(9,2));Query OK, 0 rows affected (0 ...
- java类集框架图(google找的,备个份)