a169: POJ 3225 Help with Intervals
Tags :
Accepted rate : 15人/15人 ( 100% ) [非即時]

Content

LogLoader, Inc. is a company specialized in providing products for analyzing logs. While Ikki is working on graduation design, he is also engaged in an internship at LogLoader. Among his tasks, one is to write a module for manipulating time intervals, which have confused him a lot. Now he badly needs your help.

In discrete mathematics, you have studied several basic set operations, namely union, intersection, relative complementation and symmetric difference, which naturally apply to the specialization of sets as intervals.. For your quick reference they are summarized in the table below:

OperationNotation

Definition

UnionAB{x : xA or xB}
IntersectionAB{x : xA and xB}
Relative complementationAB{x : xA but x B}
Symmetric differenceAB(AB) ∪ (BA)

Ikki has abstracted the interval operations emerging from his job as a tiny programming language. He wants you to implement an interpreter for him. The language maintains a set S, which starts out empty and is modified as specified by the following commands:

CommandSemantics
U TSST
I TSST
D TSST
C TSTS
S TSST

AB{x : xAxB}
AB{x : xAxB}

Ikki已经把他的工作里出现的区间运算抽象成一个很小的编程语言。他想你为他实现一个解析器。这个语言维护一个集合SS一开始是空集，并根据下列命令被修改：

U TSST
I TSST
D TSST
C TSTS
S TSST
Input

The input contains exactly one test case, which consists of between 0 and 65,535 (inclusive) commands of the language. Each command occupies a single line and appears like

X T

where X is one of ‘U’, ‘I’, ‘D’, ‘C’ and ‘S’ and T is an interval in one of the forms (a,b), (a,b], [a,b) and [a,b] (a, bZ, 0 ≤ ab ≤ 65,535), which take their usual meanings. The commands are executed in the order they appear in the input.

End of file (EOF) indicates the end of input.

X T

Output

Output the set S as it is after the last command is executed as the union of a minimal collection of disjoint intervals. The intervals should be printed on one line separated by single spaces and appear in increasing order of their endpoints. If S is empty, just print “empty set” and nothing else.

Sample Input
U [1,5]
D [3,3]
S [2,4]
C (1,5)
I (2,3]

Sample Output
(2,3)


Hint ：
Tags:

[管理者：
(王启圣)
]

 ID User Problem Subject Hit Post Date 沒有發現任何「解題報告」