The Game about KILL
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
Each test case only contains an integer N. (1 ≤ N ≤ 1,000,000,000)
Output
Sample Input
2 3
Sample Output
1 3
Source
Manager
题意:
就是约瑟夫环。
找个规律就行。。
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int maxn = 100000+43;
const int inf = 0x3f3f3f3f;
#define LL long long
LL sum[maxn];
int main()
{
LL n;
int i;
LL er=1;
for(i=1;;i++){
sum[i]=sum[i-1]+er;
if(sum[i]>1000000000)
break;
er=2*er;
}
while(~scanf("%lld",&n)){
int now=lower_bound(sum,sum+1+i,n)-sum;
// printf("%d\n",now);
printf("%lld\n",-1+2*(n-sum[now-1]));
}
return 0;
}

本文探讨了约瑟夫环问题的一种特殊情形,即在指定条件下确定最后一个存活者的位置。通过寻找规律,给出了一种有效的算法实现,并附带源代码进行说明。
2万+

被折叠的 条评论
为什么被折叠?



