12345678910111213141516171819202122232425262728293031 |
- #include <numeric>;
- int whoGoesFree(int n, int k) {
-
- std::vector<int> indexP(n) ;
- std::iota (std::begin(indexP), std::end(indexP), 0);
-
- int lastkill = 0, c = 0, target = 0;
-
- while(n){
-
- if(++c == k){
- lastkill = indexP[target];
-
- indexP.erase(indexP.begin() + target);
- c = 0;
- n--;
- }
-
- else{
- target = ++target % indexP.size();}
- }
- return lastkill;
- }
|