Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int GetThrowingFloor(int n) {
- int l = -1;
- int r = 33335;
- while (l < r) {
- int m = (l + r) / 2;
- if (m * (m + 1) / 2 >= n) {
- r = m;
- } else {
- l = m;
- }
- }
- int cur_pos = 1;
- int cur_pp = r;
- while (cur_pos <= n) {
- if (cur_pos + cur_pp - 1 > n) {
- while ((cur_pos <= n) && (!CheckFloor(cur_pos))) {
- cur_pos++;
- }
- break;
- } else {
- if (CheckFloor(cur_pos + cur_pp - 1)) {
- while (!CheckFloor(cur_pos)) {
- cur_pos++;
- }
- break;
- } else {
- cur_pos += cur_pp;
- cur_pp--;
- }
- }
- }
- return (cur_pos % (n + 1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement