Skip to content

Instantly share code, notes, and snippets.

@ryoppippi
Created October 12, 2015 11:52
Show Gist options
  • Select an option

  • Save ryoppippi/bcd54addad00cef6614e to your computer and use it in GitHub Desktop.

Select an option

Save ryoppippi/bcd54addad00cef6614e to your computer and use it in GitHub Desktop.
力ずくで解いたヨセフスの問題。kがならばされた人の数で、l毎に殺されていきます。本当はもっと高尚な数式とかあったけどなあ。使いたいけどそれは主旨と違う。 #coding #課題 #CodePiece
int list[k];
for ( b = 0; b < k; b++) {
list[b] = 0;
}
int alive = k;
int check = -1;
while (alive !=0) {
for (c = 0; c < l; c++) {
do {
check++;
if (check >= k) {
check -=k;
}
} while(list[check] == 1);
}
list[check] = 1;
alive -=1;
}
printf("%d\n", check+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment