CF43E.Race

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which the speed of the car is constant. The j-th segment of the i-th car is pair (v__i, j, t__i, j), where v__i, j is the car's speed on the whole segment in kilometers per hour and t__i, j is for how many hours the car had been driving at that speed. The segments are given in the order in which they are "being driven on" by the cars.

Your task is to find out how many times during the race some car managed to have a lead over another car. A lead is considered a situation when one car appears in front of another car. It is known, that all the leads happen instantly, i. e. there are no such time segment of positive length, during which some two cars drive "together". At one moment of time on one and the same point several leads may appear. In this case all of them should be taken individually. Meetings of cars at the start and finish are not considered to be counted as leads.

今天在贝尔兰举行一场长度为 ss 千米的汽车比赛。赛道是一条长度恰好为 ss 千米的直线。共有 nn 辆赛车参赛,它们全部从赛道起点处同时出发。每辆车的行为已知——即由若干段组成,每一段上其速度保持恒定。第 ii 辆车的第 jj 段行为表示为二元组 (vi,j,ti,j)(v_{i,j},\,t_{i,j}),其中 vi,jv_{i,j} 表示该车在整段上以千米/小时为单位的恒定速度,ti,jt_{i,j} 表示该车以该速度持续行驶的小时数。这些段按车辆实际行驶顺序给出。

你的任务是计算:在整个比赛过程中,某辆赛车在某一时刻领先于另一辆赛车的情形共发生了多少次。“领先”定义为一辆车位于另一辆车前方的情形。已知所有“领先”事件均瞬时发生,即不存在长度为正的时间区间,使得两辆车在此区间内“并驾齐驱”。在某一时刻,若多对车辆恰好处于同一位置(即发生多个超车事件),则每个这样的领先事件均需单独计数。车辆在起点或终点处相遇不视为领先事件,不应计入。

输入格式

The first line contains two integers n and s (2 ≤ n ≤ 100, 1 ≤ s ≤ 106) — the number of cars and the length of the track in kilometers. Then follow n lines — the description of the system of segments for each car. Every description starts with integer k (1 ≤ k ≤ 100) — the number of segments in the system. Then k space-separated pairs of integers are written. Each pair is the speed and time of the segment. These integers are positive and don't exceed 1000. It is guaranteed, that the sum of lengths of all segments (in kilometers) for each car equals to s; and all the leads happen instantly.

第一行包含两个整数 nnss2n1002 ≤ n ≤ 1001s1061 ≤ s ≤ 10^6)——分别为汽车的数量和赛道的长度(单位:千米)。接下来是 nn 行,每行描述一辆汽车的分段系统。每行描述以一个整数 kk1k1001 ≤ k ≤ 100)开头,表示该汽车的分段数量;随后是 kk 个用空格分隔的整数对,每对整数分别表示该段的速度和时间。这些整数均为正数,且不超过 10001000。保证每辆汽车所有分段的长度之和(单位:千米)恰好等于 ss;且所有超车过程均瞬间完成。

输出格式

Print the single number — the number of times some car managed to take the lead over another car during the race.

输出一个整数——即在比赛过程中,某辆赛车超越另一辆赛车的次数。

输入输出样例

  • 输入#1

    2 33
    2 5 1 2 14
    1 3 11

    输出#1

    1
  • 输入#2

    2 33
    2 1 3 10 3
    1 11 3

    输出#2

    0
  • 输入#3

    5 33
    2 1 3 3 10
    1 11 3
    2 5 3 3 6
    2 3 1 10 3
    2 6 3 3 5

    输出#3

    2

输入解题思路,AI测评打分。不知道怎么写?

首页