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

建议使用的浏览器:

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

3588:The Downloading Task

题目描述

A download software can execute multiple tasks simultaneously. For each task, there might be four states: downloading, waiting, paused, or finished. And there can be at most n tasks with state downloading at the same time. At the very beginning, the software has no tasks. Then it will receive m pieces of instructions. The forms of instructions are as listed below:

  • Sort asc: Set the priority in ascending order. The smallest name (in alphabet order) has the highest priority. This is the initial order.
  • Sort desc: Set the priority in descending order. The biggest name (in alphabet order) has the highest priority.
  • New A: Create a new task A. If the tasks with downloading state are less than n, set A's state with downloading, otherwise waiting.
  • Pause A: Set the task A with state paused. And change the task of waiting state (if there is one) with the highest priority into a downloading state.
  • Continue A: If the tasks with downloading state are less than n, set A with downloading, otherwise waiting.
  • Finish A: Set the task A with state finished. And change the task of waiting state (if there is one) with the highest priority into a downloading state.

Now you need to program to simulate the download software, output the state of all the tasks according to the final priority after it has executed all the m pieces of instructions.

Assumption: Any two different tasks have different names. The task described in the New instruction has never existed before. The task described in the Pause instruction is either waiting or downloading. The task described in the Continue instruction is paused. The task described in the Finish instruction is downloading.

输入解释

The first line of the input is an integer T which indicates the number of test cases. For each test case, the first line are two integers n (1 ≤ n ≤ 10000) and m (1 ≤ m ≤ 100000), then m lines of instructions in the forms as described above. In the instructions, names are strings contain either letters or figures with length no greater than 10.
n m
instruction[1]
instruction[2]
...
instruction[m]

输出解释

For each test case, output all the tasks' states according to the final priority, each task a line. Print a blank line after each test case.

 

输入样例
3
10 1
New name
1 5
New a
New b
New B
Pause a
Finish B
2 10
New aa
New bb
New cc
Pause aa
New dd
Continue aa
New ee
Finish cc
Sort desc
Pause bb
输出样例
name downloading

B finished
a paused
b downloading

ee downloading
dd waiting
cc finished
bb paused
aa downloading

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

源链接: POJ-3588

最后修改于 2020-10-29T07:05:19+00:00 由爬虫自动更新

共提交 0

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