博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
acd The Game about KILL(和约瑟夫归则一样,归律)
阅读量:7109 次
发布时间:2019-06-28

本文共 1216 字,大约阅读时间需要 4 分钟。

Problem Description

Teacher HU and his 40 students were trapped by the brigands. To show their power, the head of the brigands want to select one people to kill.
Teacher HU and his 40 students will stand in a circle, and every second person would leave, and the last people in the circle would be killed. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 will be killed. To make his students alive, teacher HU calculated the position to be the last man standing, and sacrifice himself.
Now we consider a more common condition, if teacher HU has N - 1 students, which place should he stand to be the last person.

Input

There are multiple test cases.
Each test case only contains an integer N. (1 <= N <= 1,000,000,000)

Output

For each test case, output an integer indicating which place should teacher HU stand.

Sample Input

23

Sample Output

13
题意:给出一个人数n,问以间隔2来去除,最后一个留下的是编号几。
归律:1:1  2:1  3:3  4:1  5:3  6:5  7:5  8:1  9:3  10:5  .......  能够看出输出的都是奇数,并且从2^k都是1,之后都是奇数递增。
 
#include
int main(){ int n,tn,m; while(scanf("%d",&n)>0) { m=1; tn=n; while(tn>1) { m*=2; tn/=2; } printf("%d\n",2*(n-m)+1); }}

转载地址:http://ynlhl.baihongyu.com/

你可能感兴趣的文章
K8S常用命令
查看>>
opencv python 优化
查看>>
PHP排序算法之插入排序
查看>>
python_bomb----拷贝与赋值
查看>>
react踩坑之旅——字符串拼接 & this不起作用
查看>>
开发一个自己的 CSS 框架(三)
查看>>
SQLServer数据库增删改查
查看>>
spring scurity session管理
查看>>
浏览器兼容(CSS部分)
查看>>
安装cuda及jcuda中遇到的问题
查看>>
使用 docker-compose 搭建一个 elk 系统
查看>>
React 学习之路 (三) 组件&props
查看>>
[前端工坊] 微信小游戏|萌狗冠军之路,纯干货分享!
查看>>
阿里巴巴java开发手册学习记录,php版
查看>>
Redux
查看>>
774. Jewels and Stones
查看>>
在react-native中添加高可维护的iconfont字体
查看>>
java中反射机制的基本语法及练习
查看>>
mac 安装 lightgbm 无法导入(以及解决cmake命令无法编译)
查看>>
three.js快速入门和实战
查看>>