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

建议使用的浏览器:

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

2938:Economic Phone Calls

题目描述

The phone you bought a long time ago has a built-in memory that keeps track of all the calls you receive. It logs the date (month and day) and the time (hour and minute) of each call along with the caller’s number. Only a limited number of calls can be logged (memory was still expensive then).

You discover that the limit is almost reached and therefore plan to delete some entries from the log. In choosing the entries to delete you have to consider two restrictions:

  1. There are some (important) entries you want to keep.
  2. You want to be able to recover the year (which the phone does not log) of each call you keep. The recovery procedure is described below.

Calculate the minimal number of entries that must be kept to satisfy these requirements.

Recovery of years

Given a list of timestamps (consisting of month, day, hour, and minute) of calls, you find out the year of each call by the following procedure:

  1. The last call in the list occurred in the current year.
  2. You compare its timestamp t to the timestamp t' of the previous call. If t' < t, you assume that both calls occurred in the same year. If t't, you assume that the previous call occurred the year before.
  3. You iterate backwards through the list and reason as in 2. at each step.

Note that this procedure is not correct in general, but you may assume that it is for the input you get, and you have to ensure that it gives the same result for the shortened log.

输入解释

The input consists of several test cases. Every test case starts with the number of entries n in the log, where 1 ≤ n ≤ 1000. Each of the next n lines contains an entry.

Every entry has the format mm:dd:HH:MM number ±, describing the month mm, day dd, hour HH, minute MM, and number (having 1–16 digits) of each call, followed by + marking a call you definitively want to keep and by - marking the other calls. The entries come directly from the log of the phone, that is, they are sorted by time of reception of the corresponding call (the last entry is the most recent).

You may assume that the recovery procedure described above yields the correct year of each call.

The last test case is followed by a 0.

输出解释

For each test case, output the minimal number of entries that must be kept to satisfy the requirements stated above. In particular, the recovery procedure described above must yield for each remaining entry the same year as derived from the corresponding input.

输入样例
7
12:31:23:59 0123456789012345 +
07:21:19:00 1337 -
01:01:00:00 0987654321 -
07:21:14:00 1337 -
11:11:11:11 11111111111 +
01:01:00:00 0123456789 +
01:01:00:00 0987654321 -
0
输出样例
6
提示

Due to an error in the phone’s software no calls have been logged on February 29.


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

题目来源 Ulm Local 2006

源链接: POJ-2938

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

共提交 0

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