#P13374. [GCJ 2011 #2] Airport Walkways

    ID: 15241 远端评测题 3000~6000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心2011Special JudgeGoogle Code Jam

[GCJ 2011 #2] Airport Walkways

题目描述

You're in an airport, standing at point 00. A corridor of length XX leads to the gate, where your plane is about to leave. There are moving walkways in the corridor, each moving with some speed wiw_i. When you walk or run on one of those, you move with speed (your speed + wiw_i). The walkways do not change their position; they just make you move faster. The walkways do not overlap: at any given point of the corridor there is at most one walkway, but one walkway can begin at the point where another ends.

Your normal walking speed is SS. You are worried that you might not catch your plane, though, so you can run a bit - you can run with speed RR for at most tt seconds in total. You do not have to run for tt consecutive seconds: you can split these tt seconds into any number of intervals, or even not use some part of them.

How long does it take you to get to the gate, assuming you choose when to walk and when to run in order to reach it as soon as possible?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing five integers: XX (the length of the corridor, in meters), SS (your walking speed, in meters per second), RR (your running speed, in meters per second), tt (the maximum time you can run, in seconds) and NN (the number of walkways).

Each of the next NN lines contains three integers: BiB_i, EiE_i and wiw_i - the beginning and end of the walkway (in meters from your starting point) and the speed of the walkway (in meters per second).

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 11) and yy is the time (in seconds) you need to reach point XX if you walk and run optimally. Answers with relative or absolute error of at most 10610^{-6} will be accepted.

3
10 1 4 1 2
4 6 1
6 9 2
12 1 2 4 1
6 12 1
20 1 3 20 5
0 4 5
4 8 4
8 12 3
12 16 2
16 20 1
Case #1: 4.000000
Case #2: 5.500000
Case #3: 3.538095238

提示

Sample Explanation

The best solution in the first case is to start running immediately and run for one second.

Limits

  • 1T401 \leq T \leq 40.
  • 1S<R1001 \leq S < R \leq 100.
  • 1wi1001 \leq w_i \leq 100.
  • 0Bi<EiX0 \leq B_i < E_i \leq X.
  • EiBi+1E_i \leq B_{i+1}.

Small dataset (8 Pts, Test set 1 - Visible)

  • 1t1001 \leq t \leq 100.
  • 1X1001 \leq X \leq 100.
  • 1N201 \leq N \leq 20.
  • Time limit: 30 3 seconds.

Large dataset (10 Pts, Test set 2 - Hidden)

  • 1t1061 \leq t \leq 10^6.
  • 1X1061 \leq X \leq 10^6.
  • 1N10001 \leq N \leq 1000.
  • Time limit: 60 6 seconds.