当前位置:   article > 正文

UVa 11627 Slalom 解题报告(二分)_uva1724 solitaire题意解读

uva1724 solitaire题意解读

Problem E: Slalom

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

You may select from S pairs of skis, where the jth pair has speedsj.Your movement is governed by the following rule: if you select a pair of skiswith 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 vhmetres 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 W, vh, andN, separated by spaces, with1 <= W <= 108,1 <= vh <= 106, and1 <= N <= 105.

The following N lines of the test case each contain two integers xiandyi, the horizontal and vertical positions respectively of theith left gate, with1 <= xi, yi <= 108.

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

The following S lines of the test case each contain one integer sj, thespeed 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 sjof the pair of skis that allows you to get through the race course in the shortest time.

Output for Sample Input

2
IMPOSSIBLE


    解题报告: 首先,题意比较难懂。简单来说就是下面这个样子:

    图很烂……黑色的线条代表gate,左边的点的坐标就是(xi, yi)。人从山上y=0的地方滑下来,垂直速度为sj, 水平速度为0 - vh。

    题目让我们求出可以通过所有gate最大速度。思路呢,自然是二分速度了。每次我们求出经过一个gate后,能到达的最左边的位置left,和最右边的位置right。与下一个gate的横坐标进行比较。如果二者有交集,那么说明可以滑进去,修正下左右位置,继续;如果不能,说明垂直速度太快了,需要用更慢的速度去滑,这样水平位移可以更大一点。

    中间求位移的地方没有直接除速度sj,而是让其他变量乘上sj,确保精度。代码如下:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <map>
  9. #include <string>
  10. using namespace std;
  11. #define ff(i, n) for(int i=0;i<(n);i++)
  12. #define fff(i, n, m) for(int i=(n);i<=(m);i++)
  13. #define dff(i, n, m) for(int i=(n);i>=(m);i--)
  14. typedef long long LL;
  15. typedef unsigned long long ULL;
  16. void work();
  17. int main()
  18. {
  19. #ifdef ACM
  20. freopen("in.txt", "r", stdin);
  21. #endif // ACM
  22. work();
  23. }
  24. /*****************************************/
  25. int x[111111], y[111111];
  26. int spd[1111111];
  27. int w, vh, n;
  28. bool check(int vv)
  29. {
  30. LL left = (LL)x[0]*vv, right = (LL)(x[0] + w)*vv;
  31. ff(i, n-1)
  32. {
  33. LL len = (LL)(y[i+1]-y[i]) * vh;
  34. if(left-len > (LL)(x[i+1]+w)*vv) return false;
  35. if(right+len < (LL)x[i+1]*vv) return false;
  36. left = max((LL)x[i+1]*vv, left-len);
  37. right = min((LL)(x[i+1]+w)*vv, right+len);
  38. }
  39. return true;
  40. }
  41. void work()
  42. {
  43. int T;
  44. scanf("%d", &T);
  45. ff(cas, T)
  46. {
  47. scanf("%d%d%d", &w, &vh, &n);
  48. ff(i, n) scanf("%d%d", x+i, y+i);
  49. int s;
  50. scanf("%d", &s);
  51. ff(i, s) scanf("%d", spd+i);
  52. sort(spd, spd+s);
  53. s = unique(spd, spd+s) - spd;
  54. int l = 0, r = s - 1;
  55. while(l <= r)
  56. {
  57. int m = (l+r)/2;
  58. if(check(spd[m]))
  59. l = m + 1;
  60. else
  61. r = m - 1;
  62. }
  63. if(r == -1)
  64. puts("IMPOSSIBLE");
  65. else
  66. printf("%d\n", spd[r]);
  67. }
  68. }


本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号