luogu#P9339. [JOISC 2023 Day3] Cookies
[JOISC 2023 Day3] Cookies
题目描述
Rie likes to make cookies. She made types of cookies. She made cookies of type . In order to sell the cookies made by her, she will pack them into boxes. However, the following conditions should be satisfied.
- For every box, the types of the cookies in it should be different.
- For every box, the number of cookies in it should be equal to one of the following numbers: .
Write a program which, given information of cookies made by Rie and the conditions to pack the cookies into boxes, determines whether it is possible to pack all the cookies into boxes. Moreover, if it is possible to pack all the cookies into boxes, your program should output a way to pack the cookies into the minimum number of boxes.
输入格式
Read the following data from the standard input.
输出格式
If it is possible to pack all the cookies into boxes so that the conditions are satisfied, let be the number of used boxes, be the number of cookies in the -th box (), and be the types of the cookies in the -th box. Write these numbers to the standard output as in the following format.
$c _ 1 \ v _ {1, 1} \ v _ {1, 2} \ \cdots \ v _ {1, c _ 1}$
$c _ 2 \ v _ {2, 1} \ v _ {2, 2} \ \cdots \ v _ {2, c _ 2}$
$c _ x \ v _ {x, 1} \ v _ {x, 2} \ \cdots \ v _ {x, c _ x}$
Here, the number of used boxes should be the minimum possible number. If there are several ways to pack the cookies into boxes satisfying the conditions, output any one of them.
If it is impossible to pack all the cookies into boxes so that the conditions are satisfied, write to the standard output.
题目大意
题目描述
莉婕喜欢做饼干。她制作了 种饼干。第 种饼干有 个。为了出售她制作的饼干,她将它们装入盒子中。但是,应该满足以下条件。
-
对于每个盒子,其中的饼干种类应不同。
-
对于每个盒子,其中的饼干数量应等于以下 个数字之一:。
编写一个程序,给出莉婕制作的饼干信息和将饼干装箱的条件,确定是否可能将所有饼干包装到盒子中。此外,如果可以将所有饼干包装在盒子中,则您的程序应输出最少的盒子数量。
输入格式
从标准输入读取以下数据。
输出格式
如果可以将所有的饼干装入盒子并且满足上述条件,则设 是所需的盒子数, 是第 个盒子中的饼干数 , 是第 个盒子中的饼干种类。请将这些数字按以下格式编写到标准输出。
$c _ 1 \ v _ {1, 1} \ v _ {1, 2} \ \cdots \ v _ {1, c _ 1}$
$c _ 2 \ v _ {2, 1} \ v _ {2, 2} \ \cdots \ v _ {2, c _ 2}$
$c _ x \ v _ {x, 1} \ v _ {x, 2} \ \cdots \ v _ {x, c _ x}$
在此,使用的盒子数量 应该是可能的最小数量。如果有多种方式可以满足条件地将饼干装入盒子,请输出其中任何一种方法。
如果无法将所有饼干包装在盒子中以满足条件,输出 。
【样例解释 #1】
对于该样例输入,可以按照以下方式将 个饼干装入 个盒子中满足条件:
- 将第 类和第 类的饼干装入第一个盒子中。每种类型放 个。
- 将第 类和第 类的饼干装入第二个盒子中。每种类型放 个。
- 将第 类、第 类和第 类的饼干装入第三个盒子中。每种类型放 个。
因为不能用少于或等于 个盒子来包装 个饼干,所以以上方法是正确的。判断为正确答案。还有其他正确方法。
Translate by
7
1 1 1 1 1 1 1
3
1 2 3
3
2 1 7
2 2 6
3 3 4 5
5
5 3 1 2 4
1
4
-1
7
5 4 4 2 1 1 1
2
2 6
7
6 1 2 3 4 5 6
2 2 1
2 3 1
2 4 1
2 7 1
2 3 2
2 3 2
提示
【样例解释 #1】
In this sample input, it is possible to pack the cookies into boxes so that the conditions are satisfied as follows.
- Pack cookies of types into the first box. Pack one cookie for each type.
- Pack cookies of types into the second box. Pack one cookie for each type.
- Pack cookies of types into the third box. Pack one cookie for each type.
Your program is judged as correct if it outputs the above way to pack the cookies because it is impossible to pack the cookies into less than or equal to boxes so that the conditions are satisfied. There are other ways to pack the cookies which are judged as correct.
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5, 6.
【样例解释 #2】
In this sample input, it is impossible to pack the cookies into boxes so that the conditions are satisfied.
Therefore, output .
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6.
【样例解释 #3】
This sample input satisfies the constraints of Subtasks 4, 5, 6.
【数据范围】
对于所有测试数据,满足 ,(),,,(),(),保证所有输入均为整数。
子任务编号 | 分值 | 限制 |
---|---|---|
,() | ||
, | ||
没有额外的限制 |