E. Meetings

Codeforces
IDCF10050E
Time1000ms
Memory64MB
Difficulty
English · Original
Formal · Original
Two cities A and B are connected by a straight road that is exactly l meters long. At the initial moment of time a cyclist starts moving from city A to city B at a speed v1 meters/second, and a pedestrian starts moving from city B to city A at a speed v2 meters/second. When one of them reaches a city, the road ends, so the person has to turn around and start moving in the opposite direction by the same road, keeping the original speed. As a result, the cyclist and the pedestrian are traveling between cities A and B indefinitely. Your task is to calculate the number of times they will meet during the first t seconds. If they meet in exactly t seconds after the initial moment of time, this meeting should also be counted. The only line of input contains four integer numbers: l, v1, v2 and t. All numbers are between 1 and 109, inclusively. Print a single integer — the number of times the cyclist and the pedestrian will meet during the first t seconds. ## Input The only line of input contains four integer numbers: l, v1, v2 and t. All numbers are between 1 and 109, inclusively. ## Output Print a single integer — the number of times the cyclist and the pedestrian will meet during the first t seconds. [samples]
**Definitions** Let $ l, v_1, v_2, t \in \mathbb{Z}^+ $ denote the road length, cyclist speed, pedestrian speed, and total time, respectively. **Constraints** $ 1 \leq l, v_1, v_2, t \leq 10^9 $ **Objective** Compute the number of meetings between the cyclist and pedestrian in the time interval $ [0, t] $, where: - The cyclist starts at position $ 0 $ (city A) moving toward $ l $ (city B) at speed $ v_1 $. - The pedestrian starts at position $ l $ (city B) moving toward $ 0 $ (city A) at speed $ v_2 $. - Upon reaching either end, each reverses direction instantaneously without loss of speed. Model their positions as periodic functions with period $ \frac{2l}{v_1} $ and $ \frac{2l}{v_2} $, respectively. The relative motion is equivalent to a single particle moving with relative speed $ v_1 + v_2 $ on a circle of circumference $ 2l $, where each meeting corresponds to covering a distance of $ 2l $ relative to each other. The number of meetings in time $ t $ is: $$ \left\lfloor \frac{(v_1 + v_2) t}{2l} \right\rfloor $$
API Response (JSON)
{
  "problem": {
    "name": "E. Meetings",
    "description": {
      "content": "Two cities A and B are connected by a straight road that is exactly l meters long. At the initial moment of time a cyclist starts moving from city A to city B at a speed v1 meters/second, and a pedest",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10050E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Two cities A and B are connected by a straight road that is exactly l meters long. At the initial moment of time a cyclist starts moving from city A to city B at a speed v1 meters/second, and a pedest...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ l, v_1, v_2, t \\in \\mathbb{Z}^+ $ denote the road length, cyclist speed, pedestrian speed, and total time, respectively.\n\n**Constraints**  \n$ 1 \\leq l, v_1, v_2, t \\leq 10^9 $\n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments