求助

灌水区

1<=n<=100000
by manong_czk @ 2024-03-27 14:52:32


显然只跟相邻两项的差有关,剩下自己想去
by jason_sun @ 2024-03-27 14:55:35


@[jason_sun](/user/399762) 感谢已关
by manong_czk @ 2024-03-27 14:57:00


蒟蒻不懂**球代码** $\color{purple}\texttt{Please!}$
by manong_czk @ 2024-03-27 15:07:39


@[manong_czk](/user/1063924) ```cpp #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f3f3f3f3fll; ll n, a[100005] = {}, d[100005], dmin = inf; // d[i] = a[i] - a[i - 1],dmin表示d[i]的最小值,即a中相邻两项的差的最小值 int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; } for (ll i = 2; i <= n; i++) { d[i] = a[i] - a[i - 1]; } for (ll i = 2; i <= n; i++) { if (d[i] < 0) { // d[i] < 0 => a[i] - a[i - 1] < 0 => a[i] < a[i - 1] cout << 0 << endl; exit(0); // 相当于在主函数内执行return 0; } dmin = min(dmin, d[i]); } cout << (dmin + 2) / 2 << endl; // 将两数的差值从dmin减到负数,则至少要减(dmin + 1) // (dmin + 1) / 2 上取整 = ((dmin + 1) + (2 - 1)) / 2 = (dmin + 2) / 2 return 0; } ```
by 0x28202e202e29 @ 2024-03-27 16:19:39


@[0x28202e202e29](/user/790188) 万般感谢大佬!已关。【叩拜】
by manong_czk @ 2024-03-27 18:13:17


@[0x28202e202e29](/user/790188) 蛋柿 ``` 5 1 2 3 4 5 ``` 这个答案应该不是 `1` 吧。
by manong_czk @ 2024-03-27 19:40:14


o,答案是 1。
by manong_czk @ 2024-03-27 19:49:18


|