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. ...
随机推荐
- IOS面试题总结
iOS面试题: 一:网络理论知识的理解 1:Internet物理地址和IP地址转换采用什么协议 ARP(Address Resolution Protocol)地址解析协议 2:Internet采用哪 ...
- msnodesql的使用
msnodesql的安装 npm install msnodesql 使用msnodesql写的增删改查 var sql=require('msnodesql'); var conn_str= ...
- jquery插件之拖拽改变元素大小
该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的拖拽改变元素大小的效果,您可以根据自己的实际需求来设置被 ...
- [LintCode] Nuts & Bolts Problem 螺栓螺母问题
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...
- 【8.0、9.0c】树形列表 列标题 不对齐的问题及解决方案
树形视图状态经常会碰到字体上下排列不整齐的问题,虽不是什么大问题,但对某些处女座的人来说,真的是如鲠在喉,今天我们就来解决这个问题: 首先呢,这个问题的起因,不是前端css的问题,也不是js的问题,而 ...
- cookie&&session再理解笔记
就拿php来说,两个php页面之间不拿get,post传递变量的话,数据是不能共享的.访问完1.php页面该页面的变量就被销毁了.所以就拿学校食堂来说,拿现金买饭的话你交完钱后,他给你个票以便确认你, ...
- 模拟实现ORM实例
https://git.oschina.net/wenjieyatou/hibernate_OR_Mapping 请参考git代码.基本原理是自己写了一个session,然后用反射机制模拟数据库存储机 ...
- vbox下Oracle Enterprise liunx5.4虚拟机安装10G RAC实验(一)
1.配置第一个虚拟机 1.1 安装后的登录界面 1.2 第1台机器(单数据配置方面) 1.2.1 验证安装包 1.2.2 修改内核参数 1.2.3添加安全限制 1.2.4关闭防火墙 1.2.5添加用户 ...
- javascript 百度地图
官方地址 http://lbsyun.baidu.com/index.php?title=jspopular 示例地址 http://developer.baidu.com/map/jsdemo.ht ...
- 歐洲國家拓展其移動和IT服務業務
中興德國子公司與JOIN簽訂了一項綜合託管服務合同,在該合同中,公司將全面負責為盧森堡和比利時的JOIN核心網路提供網路運營,點對點無線網路報告,新品發佈和維護,還負責故障檢查.維修.測試和軟體升級. ...