POJ 1781 In Danger
来源:互联网 发布:世界上最出名的程序员 编辑:程序博客网 时间:2024/05/18 22:55
In Danger
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2462 Accepted: 1294
Description
Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch).
We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!
We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest!
Input
The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then follow z zeros. Whereas 0<=x,y<=9, the number of zeros is 0<=z<=6. You may assume that n>0. The last test case is followed by the string 00e0.
Output
For each test case generate a line containing the position of the person who survives. Assume that the participants have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 is staying alive.
Sample Input
05e001e142e066e600e0
Sample Output
352164891137
Source
Ulm Local 2004
题目大意:约瑟夫环最后剩的两个人取编号小的一个
题目分析:得到规律
1 1 1..1
2 1 10..1
3 3 11..1
4 1 100..1
5 3 101..1
6 5 110..1
7 7 111..1
8 1 1000..1
左移一位位或1 去头
代码如下:
- POJ 1781 In Danger
- poj 1781 In Danger
- poj 1781-In Danger
- POJ 1781 In Danger
- POJ 1781 In Danger
- POJ 1781 In Danger 笔记
- POJ 1781 In Danger (约瑟夫问题)
- poj In Danger 约瑟夫
- POJ 2370 Democracy in danger
- POJ 2370 Democracy in Danger
- poj 2370 Democracy in danger
- POJ 1781 In Danger 约瑟夫环(log(m))
- POJ 1781 In Danger Joseph环 位运算解法
- poj 1781 In Danger(约瑟夫环,找规律)
- POJ 1781 In Danger 约瑟夫环(log(m)模板)
- Overcome ACM POJ 2370 - Democracy in danger
- A Pilot in Danger!
- poj2370 Democracy in danger!
- qq 号码简单分类
- Default Removing scrollbars from TDBCtrlGrid
- fedora11登录root账户GUI
- PHP的事务处理 MYSQL
- 在网页中在线浏览ppt文档
- POJ 1781 In Danger
- Linux DNS 进阶配置——父子域DNS
- linux samba:匿名可上传下载
- linux samba续:验证用户登录
- S60平台:Avkon UI 资源-设置列表--S60 Platform: Avkon UI Resources- Setting Lists翻译连载三
- windows利用net use删除smb连接
- python模拟mysql多客户端并发操作
- 求助
- 为什么你应该(从现在开始就)写博客