10323 - 纺车的轮子

一架纺车有五个纺轮,这五个不透明的轮子边缘上都有一些缺口。这些缺口必须被迅速而准确地排列好。每个轮子都有一个起始标记(在0度),这样所有的轮子都 可以在统一的已知位置开始转动。轮子按照?#22686;加角度?#30340;方向旋转,所以从起始位置开始,在一定的时间内,它们依次转过1度,2度 厖等等(虽然这些轮子很可能不会同时转过这些角度)。

这是一个整数问题。轮子不会转过1.5度或23.51234123度这样的角度。例如,轮子可能在一秒钟内转过20到25度甚至30到40度(如果转得快的话)。

这个问题中的所有角度都限制在 0 <= 角度 <= 359 这个范围内。轮子转过 359 度后接下来就是 0 度。每个轮子都有一个确定的旋转速度,以秒作为单位。1 <= 速度 <= 180。

轮子上的缺口的起始角度和缺口大小(或长度)各由一个整数表示,都以度为单位。在一个轮子上,两个缺口之间至少有一度的间隔。

在起始位置,设时间为 0,所有的轮子的起始标记排列成一条直线。你的程序必须计算,最早出现每个的轮子上的缺口同其他轮子上的缺口对准(也就是一束光可以通过五个轮子上的五个缺口)情况的时间。这些缺口在任意一个角度对准。

输入

输入中的五行对应五个轮子。

第一个数字表示轮子的转动速度。下一个数字是缺口的数目 W。1 <= W <= 5。接下来的 W 对数字表示每个缺口的起始角度和长度。

输出

只有一行,包括一个整数,表示光能够通过这五个轮子的最早时间。如果无解,输出搉one?#65288;小写,不含引号)。

样例

输入

30 1 0 120
50 1 150 90
60 1 60 90
70 1 180 180
90 1 180 60

输出

9

提示

Spinning Wheels 1998 ACM NE Regionals Each of five opaque spinning wheels has one or more wedges cut out of their edges. These wedges must be aligned quickly and correctly. Each wheel also has an alignment mark (at 0 degrees) so that the wheels can all be started in a known position. Wheels rotate in the `plus degrees' direction, so that shortly after they start, they pass through 1 degree, 2 degrees, etc. (though probably not at the same time).

This is an integer problem. Wheels are never actually at 1.5 degrees or 23.51234123 degrees. For example, the wheels are considered to move instantaneously from 20 to 25 degrees during a single second or even from 30 to 40 degrees if the wheel is spinning quickly.

All angles in this problem are presumed to be integers in the range 0 <= angle <= 359. The angle of 0 degrees follows the angle of 359 degrees. Each wheel rotates at a certain integer number of degrees per second, 1 <= speed <= 180.

Wedges for each wheel are specified by an integer start angle and integer angle size (or `extent'), both specified in degrees. Wedges in the test data will be separated by at least one degree.

At the start, which is time 0, all the wheels' alignment marks line up. Your program must determine the earliest time (integer seconds) at or after the start that some wedge on each wheel will align with the wedges on the other wheel so that a light beam can pass through openings on all five wedges. The wedges can align at any part of the rotation.

PROGRAM NAME: spin INPUT FORMAT Each of five input lines describes a wheel.

The first integer on an input line is the wheel's rotation speed. The next integer is the number of wedges, 1 <= W <= 5. The next W pairs of integers tell each wedge's start angle and extent.

SAMPLE INPUT (file spin.in) 30 1 0 120 50 1 150 90 60 1 60 90 70 1 180 180 90 1 180 60

OUTPUT FORMAT A single line with a single integer that is the first time the wedges align so a light beam can pass through them. Print `none' (lower case, no quotes) if the wedges will never align properly.

SAMPLE OUTPUT (file spin.out) 9

时间限制 1 秒
内存限制 128 MB
统计
上一题 下一题