题意:在一场滑雪比赛中,你需要通过n个门,所有门有严格的按海拔递减,你有S双滑雪板,第j双的速度是sj,你的水平速度不能超过vh,如果起点和终点可以任意,输出可以顺利通过的最大速度
思路:看到题目就想到了二分,但我们是在输入S双鞋的速度外面,便于求最大值,那么二分的条件是什么呢,题目简单的地方是给出了水平速度和下降速度,所以不用看到物理公式了,在任意两个门的下降时间的同时我们可以求出我们可能达到的水平的宽度,当然由于还要比较的是是否有超出门的范围,至于判断错误的条件就是x1>=x2,
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100010;
struct node{
int x,y;
}a[MAXN];
int w,v,n;
bool ok(int nv){
double x1,x2;
x1 = a[0].x;
x2 = a[0].x + w;
for (int i = 1; i < n; i++){
double temp = 1.0*v*(a[i].y-a[i-1].y)/nv;
x1 -= temp,x2 += temp;
x1 = max(x1,a[i].x*1.0);
x2 = min(x2,(a[i].x+w)*1.0);
if (x1 - x2 > 1e-10)
return false;
}
return true;
}
int main(){
int t;
scanf("%d",&t);
while (t--){
scanf("%d%d%d",&w,&v,&n);
for (int i = 0; i < n; i++)
scanf("%d%d",&a[i].x,&a[i].y);
int l = 0,r = 1000010;
while (l < r){
int mid = l + (r-l+1)/2;
if (ok(mid))
l = mid;
else r = mid - 1;
}
int ans = 0,m,t;
scanf("%d",&m);
while (m--){
scanf("%d",&t);
if (t <= l)
ans = max(ans,t);
}
if (ans)
printf("%d\n",ans);
else printf("IMPOSSIBLE\n");
}
return 0;
}