11627 - Slalom UVA

Slalom

You are competing in a ski slalom, and you need to select the best skis for the race. The format of the race is that there are  N  pairs of left and right gates, where each right gate is  W  metres to the right of its corresponding left gate, and you may neither pass to the left of the left gate nor to the right of the right gate. The  i th  pair of gates occurs at distance  yi  down the hill, with the horizontal position of the  i th  left gate given by  xi . Each gate is further down the hill than the previous gate (i.e.  yi  <  yi+1  for all i ).

You may select from S pairs of skis, where the jth pair has speed sj. Your movement is governed by the following rule: if you select a pair of skis with speed sj, you move with a constant downward velocity of sjmetres per second. Additionally, at any time you may move at a horizontal speed of at most vh metres per second.

You may start and finish at any two horizontal positions. Determine which pair of skis will allow you to get through the race course, passing through all the gates, in the shortest amount of time.

Input Specification

The first line of input contains a single integer, the number of test cases to follow.

The first line of each test case contains the three integers Wvh, and N, separated by spaces, with 1 <= W<= 108, 1 <= vh <= 106, and 1 <= N <= 105.

The following N lines of the test case each contain two integers xi and yi, the horizontal and vertical positions respectively of the ith left gate, with 1 <= xiyi <= 108.

The next line of the test case contains an integer S, the number of skis, with 1 <= S <= 106.

The following S lines of the test case each contain one integer sj, the speed of the jth pair of skis, with 1 <= sj <= 106.

Sample Input

2
3 2 3
1 1
5 2
1 3
3
3
2
1
3 2 3
1 1
5 2
1 3
1
3

Output Specification

Output one line for each test case. If it is impossible to complete the race with any pair of skis, print the line  IMPOSSIBLE . Otherwise, print the vertical speed  sj  of the pair of skis that allows you to get through the race course in the shortest time.

Output for Sample Input

2
IMPOSSIBLE

一定要注意二分时候的界限!!!!!
在判断当前sj下能够穿过所有门时,可以自顶向下,逐步约束人能够到达的x坐标上的范围,直到这个范围变成空集或者所有的门都经过了为止
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
using namespace std;
const int maxn = 10;
int W,V,N;
struct pos
{
    int x;
    int y;
}p[100000 + maxn];
int ok(int v)
{
    double x1 = p[0].x;
    double x2 = p[0].x+W;
    for(int i = 1;i<N;++i)
    {
        double d = (double)(p[i].y-p[i-1].y)/v*V;
        x1 -= d;
        x2 += d;
        x1 = max(x1,(double)p[i].x);
        x2 = min(x2,(double)p[i].x+W);
        if(x1>x2+1e-6) return 0;
    }
    return 1;
}
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    for(i = 0;i<n;++i)
    {
        scanf("%d%d%d",&W,&V,&N);//门宽度,最大横向速度,门个数
        int j;
        for(j = 0;j<N;++j)
            scanf("%d %d",&p[j].x,&p[j].y);
        int L = 0;
        int R = 1000010;
        int mid;
     for(;;)
    {
        mid = (R - L) / 2 + L;
        if(mid == L) break;
        if(ok(mid)) L = mid;
        else R = mid;
    }
        int fast = 0;
        int S;
        scanf("%d",&S);//滑板数目
        for(j = 0;j<S;++j)
        {
            int speed;
            scanf("%d",&speed);
            if(speed<=mid)
            fast = max(fast,speed);
        }
         if(fast==0)
         printf("IMPOSSIBLE\n");
         else
         printf("%d\n",fast);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值