Problem E: 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 areNpairs of left and right gates, where each right gate isWmetres
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. Theithpair
of gates occurs at distanceyidown the hill, with the horizontal position of theithleft
gate given byxi. Each gate is further down the hill than the previous gate (i.e.yi<yi+1for
alli).
You may select fromSpairs of skis, where thejthpair has speedsj. Your movement is governed by the following rule: if you select a pair of skis with speedsj, you move with a constant downward velocity ofsjmetres per second. Additionally, at any time you may move at a horizontal speed of at mostvhmetres 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 integersW,vh, andN, separated by spaces, with 1 <=W<= 108, 1 <=vh<= 106, and 1 <=N<= 105.
The followingNlines of the test case each contain two integersxiandyi, the horizontal and vertical positions respectively of theithleft gate, with 1 <=xi,yi<= 108.
The next line of the test case contains an integerS, the number of skis, with 1 <=S<= 106.
The followingSlines of the test case each contain one integersj, the speed of thejthpair 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 lineIMPOSSIBLE. Otherwise, print the vertical speedsjof the pair of skis that allows you to get through the race course in the shortest time.Output for Sample Input
2 IMPOSSIBLE
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 100005;
int T, n, S, s[N * 10];
double w, v;
struct Sk {
double s, e, y;
} sk[N];
void init() {
scanf("%lf%lf%d", &w, &v, &n);
for (int i = 0; i < n; i ++) {
scanf("%lf%lf", &sk[i].s, &sk[i].y);
sk[i].e = sk[i].s + w;
}
scanf("%d", &S);
for (int i = 0; i < S; i ++)
scanf("%d", &s[i]);
sort(s, s + S);
}
bool judge(int sv) {
double s = sk[n - 1].s, e = sk[n - 1].e;
for (int i = n - 1; i > 0; i --) {
double time = (sk[i].y - sk[i - 1].y) / sv;
s = max(s - time * v, sk[i - 1].s);
e = min(e + time * v, sk[i - 1].e);
if (s > sk[i - 1].e || e < sk[i - 1].s || s > e)
return false;
}
return true;
}
void solve() {
if (!judge(s[0])) {
printf("IMPOSSIBLE\n");
return;
}
int l = 0, r = S - 1;
while (l < r) {
int mid = (l + r)>>1;
if (judge(s[mid])) l = mid + 1;
else r = mid;
}
if (!judge(s[l]))
l--;
printf("%d\n", s[l]);
}
int main() {
scanf("%d", &T);
while (T--) {
init();
solve();
}
return 0;
}
413

被折叠的 条评论
为什么被折叠?



