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 ith pair of gates occurs at distance yi down the hill, with the horizontal position of the ith left gate given by xi. Each gate is further down the hill than the previous gate (i.e. yi < yi+1 for alli).
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 sj metres 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.
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 W, vh, 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 <= xi, yi<= 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.
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 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.
2
IMPOSSIBLE
题目大意:在一场滑雪比赛中,你需要通过N个旗门,第i个旗门的左端坐标为Xi,每个旗门的宽度都为W,第i个旗门离山顶的距离为Yi,N个旗门的距离山顶的距离是严格递增的,即Yi<Y(i+1)。你有S双滑雪鞋,每双垂直速度为Si,水平速度是可以变化的,但不超过Vh。起点和终点可以任选,要求你求出可以通过N个旗门的鞋子的最大速度。
题解:可以二分鞋子的速度。然后判断该速度的鞋子能否通过N个旗门,判断从旗门i能否滑到旗门i+1的方法是:计算出旗门i滑到到旗门i+1水平高度时它可以到达的区间范围,然后用这个区间和旗门i+1求交集,如果为空集则说明从旗门i不能达到旗门i+1。PS:撸出来之后一直WA,后来发现是把区间定义为整数了。。修改之后依然WA。。。找了N就才发现,我定义了个全局变量n,然后在主函数里又定义了一个变量n。。。修改之后提交到UVa上显示RE,认真检查发现,是记录速度的数组开小了。。。。各种坑啊。
1 #include<stdio.h> 2 #include<stdlib.h> 3 #define MAXN 100005 4 #define INF 0x7fffffff 5 typedef struct 6 { 7 long x,y; 8 }COOR; 9 COOR t[MAXN]; 10 long speed[MAXN*10]; 11 long w,n,v,s; 12 double min(double a,double b) 13 { 14 return a<b?a:b; 15 } 16 double max(double a,double b) 17 { 18 return a>b?a:b; 19 } 20 int check(long x) 21 { 22 long i; 23 double l,r; 24 l=t[0].x; r=t[0].x+w; 25 for(i=1;i<n;i++) 26 { 27 double d=((double)t[i].y-t[i-1].y)*v/x; 28 l-=d; r+=d; 29 l=max(t[i].x,l); r=min(t[i].x+w,r); 30 if(l>r) return 0; 31 } 32 return 1; 33 34 } 35 int main(void) 36 { 37 long i,l,r,maxs,m,T,ans; 38 scanf("%ld",&T); 39 while(T--) 40 { 41 scanf("%ld%ld%ld",&w,&v,&n); 42 for(i=0;i<n;i++) 43 scanf("%ld%ld",&t[i].x,&t[i].y); 44 scanf("%ld",&s); 45 maxs=-1; 46 for(i=0;i<s;i++) 47 { 48 scanf("%ld",&speed[i]); 49 if(speed[i]>maxs) maxs=speed[i]; 50 } 51 l=0; r=maxs; 52 while(l<r) 53 { 54 m=l+(r-l+1)/2; 55 if(check(m)) l=m; else 56 r=m-1; 57 } 58 ans=-1; 59 for(i=0;i<s;i++) 60 if(speed[i]<=l&&speed[i]>ans) ans=speed[i]; 61 if(ans==-1) printf("IMPOSSIBLE\n"); 62 else 63 printf("%ld\n",ans); 64 } 65 return 0; 66 }