mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create Josephus_problem.cpp
This commit is contained in:
parent
dfd5eedf5f
commit
1d41e9317e
12
.ACM-Templates/Josephus_problem.cpp
Normal file
12
.ACM-Templates/Josephus_problem.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
///约瑟夫问题,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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user