Last active
June 12, 2022 07:17
-
-
Save htoann/660c0289b7507e9f971d0a387560abb6 to your computer and use it in GitHub Desktop.
Josephus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
void josephus2(int n, int k) { | |
queue < int > q; | |
for (int i = 1; i <= n; i++) q.push(i); | |
int d = n, v = 0, x; | |
while (d > 1) { | |
int x = q.front(); | |
q.pop(); | |
++v; | |
if (v == k) { | |
d--; | |
v = 0; | |
} else q.push(x); | |
} | |
cout << "\n Phan tu con sot lai la: " << q.front(); | |
} | |
int main() { | |
josephus2(9, 2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment