当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1304:World's Worst Bus Schedule

题目描述
You are a very impatient person, and hate to be kept waiting. You are on your way to visit a relative all the way in New Orleans. The problem is that the bus station you are at has the world's worst bus schedule! There are no arrival or departure times listed, only route durations for each bus running. Being the impatient person you are, you whip out your laptop and attempt to write a program that will determine how long you will have to wait before the next bus comes. Hey, you have nothing better to do, right?
输入解释
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.


A single data set has 3 components:

  1. Start line - A single line, "START N", where N is the number of buses running and 1 <= N <= 20.
  2. Route Duration line - There will be N of these lines, and each line will consist of M route durations (where 1 <= M <= 10), which will signify how long it will take each bus to return to the bus station after completing a particular route. A route duration will be represented as an integer between 1 and 1000 (inclusive).
  3. Arrival Time - There will only be one of these lines per data set. This line represents the time that you arrived at the bus station and began waiting. This is simply the number of time units that you arrived at the bus station after the buses began running (all buses begin running at time 0). This number is represented as a positive integer (yes, it can be 0 as well, this would signify arriving at the bus station as the buses begin running).
  4. End line - A single line, "END".

Following the final data set will be a single line, "ENDOFINPUT".
输出解释
For each data set, there will be exactly one line of output. This line will simply be the number of time units you will have to wait before the next bus comes after you arrive. You hate waiting so much that you will just get on the first bus that returns to the station. Let's hope this is the bus to New Orleans!

Notes

  1. All buses continuously go on their routes, starting back up with their first route after their last route is done.
  2. If the passenger's arrival time coincides with any of the bus' route departure times, he/she catches the bus at that time.
输入样例
START 3
100 200 300
400 500 600
700 800 900
1000
END
START 3 
100 200 300 4 3 2 4 2 22 
800
10 1000
32767
END
ENDOFINPUT
输出样例
200
20

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 South Central USA 2002

源链接: POJ-1304

最后修改于 2020-10-29T06:00:34+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000