D. Walker

Codeforces
IDCF10290D
Time1000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
As a world-famous traveler, Prof. Pang's research interest is to travel as many places as possible in his life. We have a segment $[ 0, n ]$. There are two travelers on it. The first one is on position $p_1$ with velocity $v_1$ (which means s/he can walk $v_1$ unit on the segment per second). The second one is on position $p_2$ with velocity $v_2$. From their respective beginning points, travelers can walk on the segment. They cannot walk outside the segment. Whenever they want to change their direction, they can turn around immediately. Please help Prof. Pang to calculate the minimum possible time by which every position of the segment is passed by at least one traveler. The first line contains one integer $t e s t med (1 <= t e s t <= 10000)$ – the number of test cases. The $i$-th of the next $t e s t$ lines contains five numbers $n, p_{1 , i}, v_{1 , i}, p_{2 , i}, v_{2 , i}$ ($0 < n <= 10000$, $0 <= p_{1 , i}, p_{2 , i} <= n$, $0. 001 <= v_{1 , i}, v_{2 , i} <= 1000$). All numbers have at most $3$ digits after the decimal point. For each test case, we should output one number – the minimum time that every position of the segment is passed by at least one traveler. Your answer is considered correct if its absolute or relative error does not exceed $10^(-6)$. ## Input The first line contains one integer $t e s t med (1 <= t e s t <= 10000)$ – the number of test cases.The $i$-th of the next $t e s t$ lines contains five numbers $n, p_{1 , i}, v_{1 , i}, p_{2 , i}, v_{2 , i}$ ($0 < n <= 10000$, $0 <= p_{1 , i}, p_{2 , i} <= n$, $0. 001 <= v_{1 , i}, v_{2 , i} <= 1000$). All numbers have at most $3$ digits after the decimal point. ## Output For each test case, we should output one number – the minimum time that every position of the segment is passed by at least one traveler.Your answer is considered correct if its absolute or relative error does not exceed $10^(-6)$. [samples]
**Definitions** Let $ t \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, t\} $: - Let $ n_k \in \mathbb{R}^+ $ denote the length of the segment $[0, n_k]$. - Let $ p_{1,k}, p_{2,k} \in [0, n_k] $ be the initial positions of traveler 1 and traveler 2. - Let $ v_{1,k}, v_{2,k} \in \mathbb{R}^+ $ be their respective constant velocities. **Constraints** 1. $ 1 \le t \le 10000 $ 2. $ 0 < n_k \le 10000 $ 3. $ 0 \le p_{1,k}, p_{2,k} \le n_k $ 4. $ 0.001 \le v_{1,k}, v_{2,k} \le 1000 $ **Objective** Find the minimum time $ T_k \in \mathbb{R}^+ $ such that every point in $[0, n_k]$ is visited by at least one traveler, where each traveler may start at $ p_{i,k} $, move with speed $ v_{i,k} $, and reverse direction instantaneously at any time within $[0, n_k]$. That is, $$ T_k = \min \left\{ t \ge 0 \,\middle|\, [0, n_k] \subseteq \bigcup_{i=1}^2 \left\{ p_{i,k} + v_{i,k} \cdot s \cdot d_i \,\middle|\, s \in [0,t],\, d_i \in \{-1,1\} \right\} \cap [0, n_k] \right\} $$
API Response (JSON)
{
  "problem": {
    "name": "D. Walker",
    "description": {
      "content": "As a world-famous traveler, Prof. Pang's research interest is to travel as many places as possible in his life. We have a segment $[ 0, n ]$. There are two travelers on it. The first one is on positi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10290D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "As a world-famous traveler, Prof. Pang's research interest is to travel as many places as possible in his life.\n\nWe have a segment $[ 0, n ]$. There are two travelers on it. The first one is on positi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ t \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, t\\} $:  \n- Let $ n_k \\in \\mathbb{R}^+ $ denote the length of the segment $[0, n_k]$.  \n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments