ACdream - 1020 - The Game about KILL(找规律)

The Game about KILL

Time Limit: 2000/1000MS (Java/Others)  Memory Limit: 128000/64000KB (Java/Others)
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
Source
dut200901102


刚开始想了会除了暴力就完全没有思路了,然后就打表看看,规律就出来了

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define LL long long
LL n,b[50],base = 2;
int main()
{
	b[0] = 0;
	for(int i=1;i<=30;i++){
		b[i] = base - 1;
		base <<= 1;
	}
	while(scanf("%lld",&n)!=EOF){
		for(int i=0;i<=30;i++){
			if(b[i]>=n){
				LL m = n - b[i-1];
				printf("%lld\n",1+2*(m-1));
				break;
			}
		}
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值