NCPC 2016 Final

充滿回憶的比賽,尤其是B QAQ

B

簡單爆搜。

Hint

Solution

AC Code

 1#include <bits/stdc++.h>
 2
 3using namespace std;
 4
 5typedef long long ll;
 6
 7ll solve(ll n)
 8{
 9    if (n == 2) {
10        return 1;
11    }
12
13    int ans = 1;
14    ll orig = n;
15    for (; ans < 33; ans++) {
16        n = orig;
17        ll sum = ans;
18
19        n -= ans;
20        for (int i = 0; i < ans; i++) {
21            if (n - (ans - i + 1) == 0)
22                return ans;
23            n -= sum + 1;
24            sum += sum + 1;
25        }
26
27        if (n <= sum + 1)
28            break;
29    }
30
31    return ans;
32}
33
34int main()
35{
36#ifndef DEBUG
37    int ncase;
38    scanf("%d", &ncase);
39    while (ncase--) {
40        ll n;
41        scanf("%lld", &n);
42        printf("%lld\n", solve(n));
43    }
44#else
45    for (int i = 2; i <= 100; i++) {
46        printf("n = %d, %lld\n", i, solve(i));
47    }
48#endif
49
50    return 0;
51}