题目描述
In computer science and mathematics, the Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game.People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.The problem — given the number of people, starting point, direction, and number to be skipped — is to choose the position in the initial circle to avoid execution. ——Wikipedia.
But now, you are not going to solve normal Josephus Problem. We change the skipping number into a dynamic number which means each round the number will change. For convenience, the skipping number t=f(x). x is the round number(starts at 1), and f is a linear function.
输入输出格式
There are many test cases.For each case, there are three numbers in a line.n,k,b. n is the number of people(numbered from 1 to n). k and b represent the linear function.1<n<1000,0<=k<50,0<=b<100
For each case print your answer.
输入输出样例
#include<bits/stdc++.h>
using namespace std;
/*
@第七只狐狸
*/
int main()
{
int n,k,b;
while(cin>>n>>k>>b)
{
int round=n-1,ans=0;
int d=round*k+b;
for(int i=2;i<=n;i++)
{
ans=(ans+d)%i;
//更新d;因为是从后往前逆推的,所以是round--
round--;
d=round*k+b;
}
cout<<ans+1<<endl;
}
}