P10781 题解

· · 题解

思路

首先不难发现 t 是一个单峰函数且开口向下,所以我们只要依次枚举时间,一旦发现温度有不上升的趋势就输出。

代码

# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n, k;
double now;
int main () {
    ios::sync_with_stdio (0);
    cin.tie (0);
    cout.tie (0);
    cin >> t;
    while (t --) {
        now = 0;
        cin >> n >> k;
        for (int i = 1; i <= n; ++ i)
            if (now / i + k <= now)
                goto print;
            else
                now = now / i + k;
print:
        cout << fixed << setprecision (1) << now << '\n';
    }
    I AK IOI
}