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

建议使用的浏览器:

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

1333:Christmas Gifts

题目描述
A pleasant headache that parents have every year is preparing Christmas gifts for their children. Because each child envies each other having seen what others received, the parents have to prepare gifts so that no child should envy any other child.

Before a husband and wife go for Christmas shopping, they announce to their children a fixed set of gift candidates and declare that each child will receive a subset of the candidates. The children then respond to the parents with conditions for them to be happy. Each child's condition is relatively defined in terms of the gifts that other siblings would have. The goal of the parents is to satisfy all their children's conditions with the smallest such gift set for each child.

Each child's condition is always expressed as a conjunction:

I need at least (a1 and a2 and ... and an)
where each ai is either
[type 1] a constant subset of the gift candidates, or
[type 2] one sibling's name (meaning his/her gifts), or
[type 3] "common-things-of" two ai of type 1 or 2 (meaning the gifts that are common among the two), or
[type 4] one sibling's name followed by "except-for" a constant subset of the gift candidates (meaning the sibling's gifts excluding those in the constant subset).
For example, for three children {X, Y, Z} and for three candidates {a, b, c} for gifts, let the condition for each child be:
X needs at least ({a, b} and common-things-of (Y, Z))
Y needs at least (common-things-of (Z, {b, c}))
Z needs at least ({a} and (X except-for {c}))
Then the smallest gifts for each child that satisfy his/her condition are {a, b} for X, {b} for Y, and {a, b} for Z.
输入解释
The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Gift candidates are numbered from 1 to n ( 1<=n<=1000 ). Children are numbered from 1 to m (1<=m<=100). The input is a sequence of non-empty lines:

The first line has the number (T) of test cases. The sequence of test cases is from the second line.
The first line of each test case has two integers, the number (n) of gift candidates followed by the number (m) of children.
The next lines show the sequence of children's conditions in the order of child 1's, child 2's,..., child m's. Each child's condition is expressed as follows:
----The first line has two integers, the child's identification and the number of ai's
----From the second line, one line represents one part (the ai) of the child's condition. Each line for starts with its type:
"-1" for type 1, "-2" for type 2, "-3" for type 3, and "-4" for type 4.
[type 1] "-1" is followed by a number k and a sequence of integers for the gift elements. The k is the number of integers in the sequence. It represents a constant set of gift candidates. For example,
-1 2 1 2
represents a set {1, 2} of gifts.
[type 2] "-2" is followed by a single integer for a sibling's identification. For example,
-2 2
represents sibling 2's gifts.
[type 3] "-3" is followed by a sequence of two formats of type 1 or 2. For example,
-3 -2 3 -1 2 2 3
represents the common-things-of sibling 3's gifts and set {2, 3}. As another example,
-3 -2 2 -2 3
represents the common-things-of sibling 2's and 3's gifts.
[type 4] "-4" is followed by type 2 followed by type 1. For example,
-4 -2 1 -1 1 3
represents sibling 1's gifts except-for {3}.
输出解释
The output is the sequence of solutions for the given test cases. The solutions are printed in the order of the test cases. Each solution is the sequence of lines, one line per child, in the increasing order of children's identification numbers. Each line starts with the child's identification number followed by his/her gift identification numbers in the increasing order. For an empty gift, only the child number is printed.
输入样例
3
2 2
1 1
-1 1 1
2 1
-4 -2 1 -1 1 1
1 1
1 1
-3 -1 1 1 -1 1 1
3 3
1 2
-1 2 1 2
-3 -2 2 -2 3
2 1
-3 -2 3 -1 2 2 3
3 2
-1 1 1
-4 -2 1 -1 1 3
输出样例
1 1
2
1 1
1 1 2
2 2
3 1 2

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

题目来源 Taejon 2002

源链接: POJ-1333

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

共提交 0

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