题目大意:一共n天,给出第m天爬到k米高,每天最多爬1m或者下降1m,求最高的可能性高度是多高
水水的数学题,因为k=1,画出来就是一个等腰直角梯形,算出公式即可。
另外,注意一下第一个记录距第一天,和最后一个记录距第n天也要考虑进去,最开始没考虑,wa了一发。
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #include<queue> #include<vector> #include<cmath> #include<ctime> #define mx 200005 #define LL long long #define mod 1000000009 #define esp 1e-12 #define y1 y1234 #define inf 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const double PI = acos(-1.0); using namespace std; struct{ int d, h; }a[100005]; int main(){ int n, m; cin >> n >> m; for (int i = 0; i < m; i++){ scanf("%d %d", &a[i].d, &a[i].h); } int ans = a[0].h + a[0].d - 1; for (int i = 1; i < m; i++){ int x = a[i - 1].h; int y = a[i].h; if (x > y)swap(x, y); int h = y - x; int w = a[i].d - a[i - 1].d; if (h>w){ printf("IMPOSSIBLE\n"); return 0; } int k = (w + h) / 2 + x; if (k > ans)ans = k; } if (n - a[m - 1].d + a[m - 1].h > ans) ans = n - a[m - 1].d + a[m - 1].h; printf("%d\n", ans); return 0; }