|
|
back to boardWrong answer on Test Case 4: Posted by FN2187 1 May 2018 11:13 Here is my code: int main() { int N, K; cin >> N >> K; int connect = 1; int temp = N; int largepow = 0; // calculate the largest power of 2 less than K while(temp > 0) { if(pow(2, largepow) < K && pow(2, largepow + 1) < K) largepow++; temp /= 2; } N--; int count = 0; // count the hours while(N > 0) { N -= connect; count++; if(connect < pow(2, largepow)) connect *= 2; else if(connect >= pow(2, largepow) && connect < K) connect++; } cout << count; return 0; } Got WA4, then I tried something else: int main () { long long n, k, exp; cin >> n >> k; for (exp = 0; (1 << exp) < n && (1 << exp) < k; exp++) if ((1 << exp) < n) exp += ((n - (1 << exp) - 1) / k) + 1; cout << exp; return 0; } Test case 4 again. What is wrong? |
|
|