codeforces 538c

题目大意:一共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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值