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

2
3

Sample Output

1
3
题意:给出一个人数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<stdio.h>
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);
}
}

acd The Game about KILL(和约瑟夫归则一样,归律)的更多相关文章

  1. 简洁之美 -约瑟夫环的python 解法

    问题描述: 约瑟夫环问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到k的那个人出列:他的下一个人又从1开始报数,数到k的那个人又出列:依此规律重复下 ...

  2. POJ3750: 小孩报数问题+一道经典约瑟夫问题(猴子选大王)

    又一次因为一个小错误,POJ上Wrong Answer了无数次..... 在差不多要放弃的时候,发现了这个猥琐的不能再猥琐的bug,改完了提交就AC了,简直无语.... 本题wo采用模拟方法: 1 # ...

  3. Roman Roulette(约瑟夫环模拟)

    Roman Roulette Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. hdu 1443 Joseph【约瑟夫环】

    题目 题意:一共有2k个人,分别为k个好人和k个坏人,现在我们需要每隔m个人把坏人挑出来,但是条件是最后一个坏人挑出来前不能有好人被挑出来..问最小的m是多少 约瑟夫环问题,通常解决这类问题时我们把编 ...

  5. python - 约瑟夫问题

    在罗马人占领乔塔帕特后,39 个犹太人与约瑟夫及他的朋友躲到一个洞中.39个犹太人决定宁愿死也不要被敌人俘虏,商定一种特殊的方式自杀,41个人排成一个圆圈,由第1个人开始报数,每报到第3人该人就必须自 ...

  6. BNUOJ 13098 约瑟夫环问题

    C. Josephus Problem 题目链接:http://www.bnuoj.com/v3/contest_show.php?cid=7095#problem/C 题目描述   The hist ...

  7. ORACLE快速彻底Kill掉的会话

    在ORACLE数据库当中,有时候会使用ALTER SYSTEM KILL SESSION 'sid,serial#'杀掉一个会话进程,但是使用这个SQL语句杀掉会话后,数据库并不会立即释放掉相关的资源 ...

  8. SQL Server会话KILL不掉,一直处于KILLED /ROLLBACK状态情形浅析

    今天遇到一个很奇怪的情况,发现一个会话异常,这个会话只是在执行一个简单的存储过程,里面使用了链接服务器(Linked Server)查询另外一台服务器数据(存储过程里面没有任何显性事务.UPDATE. ...

  9. Linux 信号(一)—— kill 函数

    世事并无好坏之分,全看我们怎么去想.—— 哈姆雷特·第二幕第二景 ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 #include <signal.h ...

随机推荐

  1. POJ 3253 Fence Repair(哈夫曼编码)

    题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个 ...

  2. s3cmd : Add a config parameter to enable path-style bucket access 当ceph rgw使用域名时,需要支持 path-style bucket特性

    s3cmd 要是1.6.1 之后的版本 增加配置项:  vi .s3cfg use_path_mode = True 源码参考: cat  /usr/local/lib/python2.7/dist- ...

  3. 转载:C++ typename的起源与用法

    转载:http://feihu.me/blog/2014/the-origin-and-usage-of-typename/#typename 侯捷在Effective C++的中文版译序中提到: C ...

  4. Elasticsearch分片&副本分配

    集群索引中可能由多个分片构成,并且每个分片可以拥有多个副本,将一个单独的索引分为多个分片,可以处理不能在单一服务器上运行的 大型索引. 由于每个分片有多个副本,通过副本分配到多个服务器,可以提高查询的 ...

  5. Java StringJoiner

    Java StringJoiner Java added a new final class StringJoiner in java.util package. It is used to cons ...

  6. ref:mysql命令大全

    Mysql常用命令行大全 ref:https://www.cnblogs.com/bluealine/p/7832219.html 1)查看表结构:desc table_name; 2)查看创建表的s ...

  7. shell 从变量中切割字符串

    1. 在shell变量中切割字符串 shell中截取字符串的方法有很多中,${expression}一共有9种使用方法.${parameter:-word}${parameter:=word}${pa ...

  8. Java常用工具类之RegexpUtils,正则表达式工具类

    package com.test.core.util; import org.apache.log4j.Logger; import org.apache.oro.text.regex.Malform ...

  9. snort安装--daq,dnet---ERROR! dnet header not found, go get it from...等错误解决方案

    snort源码安装过程中,需要安装daq,dnet.这里想说下如何进行安装.daq简单,源码下载直接安装就可以.dnet在安装过程中,出错后总想着在网上搜一搜,结果很失望..本篇记录的不仅仅是解决安装 ...

  10. 利用gmpy2破解rsa

    gmpy2的相关文档: https://gmpy2.readthedocs.io/en/latest/ ================ 题目: 来自实验吧的rsarsa:http://www.shi ...