mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
13 lines
265 B
C++
13 lines
265 B
C++
|
///约瑟夫问题,n个人,查m个数
|
||
|
int JosephusProblem_Solution4(int n, int m)
|
||
|
{
|
||
|
if(n < 1 || m < 1)
|
||
|
return -1;
|
||
|
|
||
|
vector<int> f(n+1,0);
|
||
|
for(unsigned i = 2; i <= n; i++)
|
||
|
f[i] = (f[i-1] + m) % i;
|
||
|
|
||
|
return f[n];
|
||
|
}
|