Title Description:
Give n personal siege a ring, starting from the M number, every time k-1 individuals (from the last person killed in the next number K, the first K-man was killed), ask the last remaining person is the date.
BC 75 field has a side shape, uvalive3882 is also a deformation;
Ideas:
We can solve it by hand, setting F[n] indicates who is the nth person killed.
First we numbered people starting with 0 and then 0~n-1.
f[1] = 0;
The first time we killed the k-1, and then we re-numbered, starting with the original K, numbering number No. 0,
Then if we know who the remainder of the remaining n-1 is, then this person's number is added to the value of K;
And then push back a bit.
Well, we know that in the end, when there is a person, his number must be 0, and must die, so there is the above f[1] = 0;
So what was his last number?
If k = 3, then his number should be (0+3)%2 = 1;
Let's verify that 0, 1, 0, 0 are dead, 1 are left. That's right.
So.... It is very simple, the hand push is over, remember to add 1;
/************************************************************************* > File Name:uvalive3882.cpp > Author:baiyan > Test Instructions: > Created time:2016 May 28 Saturday 17:08 47 sec. *************************************************** *******************/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intf[10005];intMain () {intn,m,k; while(SCANF ("%d%d%d", &n,&k,&m)!=eof && (n| | k| |m) {memset (f),0,sizeof(f)); f[1]=0; for(intI=2; i<=n;i++) { if(i<N) f[i]= (f[i-1]+K)%i; ElseF[i]= (f[i-1]+M)%i; //This is the number of people who are currently killed.} printf ("%d\n", f[n]+1); } return 0;}
Joseph Ring Question