CF1761C.Set Construction
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a binary matrix b (all elements of the matrix are 0 or 1) of n rows and n columns.
You need to construct a n sets A1,A2,…,An, for which the following conditions are satisfied:
- Each set is nonempty and consists of distinct integers between 1 and n inclusive.
- All sets are distinct.
- For all pairs (i,j) satisfying 1≤i,j≤n, bi,j=1 if and only if Ai⊊Aj. In other words, bi,j is 1 if Ai is a proper subset of Aj and 0 otherwise.
Set X is a proper subset of set Y, if X is a nonempty subset of Y, and X=Y.
It's guaranteed that for all test cases in this problem, such n sets exist. Note that it doesn't mean that such n sets exist for all possible inputs.
If there are multiple solutions, you can output any of them.
给你一个 n 行 n 列的二进制矩阵 b(矩阵中所有元素均为 0 或 1)。
你需要构造 n 个集合 A1,A2,…,An,使得满足以下条件:
- 每个集合非空,且均由 1 到 n(含端点)之间的互异整数构成;
- 所有集合互不相同;
- 对于所有满足 1≤i,j≤n 的数对 (i,j),bi,j=1 当且仅当 Ai⊊Aj。换言之,当且仅当 Ai 是 Aj 的真子集时,bi,j=1;否则为 0。
集合 X 是集合 Y 的真子集,当且仅当 X 是 Y 的非空子集,且 X=Y。
本题保证:对所有测试用例,均存在满足要求的 n 个集合。(注意:这并不意味着对所有可能的输入都存在这样的 n 个集合。)
若存在多种解法,输出任意一种即可。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of test cases follows.
The first line contains a single integer n (1≤n≤100).
The following n lines contain a binary matrix b, the j-th character of i-th line denotes bi,j.
It is guaranteed that the sum of n over all test cases does not exceed 1000.
It's guaranteed that for all test cases in this problem, such n sets exist.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
第一行包含一个整数 n(1≤n≤100)。
接下来的 n 行包含一个二进制矩阵 b,其中第 i 行的第 j 个字符表示 bi,j。
保证所有测试用例的 n 之和不超过 1000。
保证本题中所有测试用例均存在满足条件的 n 个集合。
输出格式
For each test case, output n lines.
For the i-th line, first output si (1≤si≤n) — the size of the set Ai. Then, output si distinct integers from 1 to n — the elements of the set Ai.
If there are multiple solutions, you can output any of them.
It's guaranteed that for all test cases in this problem, such n sets exist.
对于每个测试用例,输出 n 行。
对于第 i 行,首先输出 si (1≤si≤n) —— 即集合 Ai 的大小;然后输出 si 个互不相同的、取值范围在 1 到 n 之间的整数 —— 即集合 Ai 的元素。
若存在多种解法,输出任意一种即可。
本题保证:对所有测试用例,均存在满足条件的 n 个集合。
输入输出样例
输入#1
2 4 0001 1001 0001 0000 3 011 001 000
输出#1
3 1 2 3 2 1 3 2 2 4 4 1 2 3 4 1 1 2 1 2 3 1 2 3
说明/提示
In the first test case, we have A1=1,2,3,A2=1,3,A3=2,4,A4=1,2,3,4. Sets A1,A2,A3 are proper subsets of A4, and also set A2 is a proper subset of A1. No other set is a proper subset of any other set.
In the second test case, we have A1=1,A2=1,2,A3=1,2,3. A1 is a proper subset of A2 and A3, and A2 is a proper subset of A3.
在第一个测试用例中,我们有 A1=1,2,3,A2=1,3,A3=2,4,A4=1,2,3,4。集合 A1,A2,A3 均为 A4 的真子集,且集合 A2 也是 A1 的真子集。其余任意两个集合之间均不存在真子集关系。
在第二个测试用例中,我们有 A1=1,A2=1,2,A3=1,2,3。A1 是 A2 和 A3 的真子集,且 A2 是 A3 的真子集。
输入解题思路,AI测评打分。不知道怎么写?