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

建议使用的浏览器:

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

7074:Little prince and the garden of roses

Special Judge 特殊评判
题目描述
He was standing before a garden, all a-bloom with roses.
"Good morning," said the roses.
The little prince gazed at them. They all looked like his flower.
"Who are you?" he demanded, thunderstruck.
"We are roses," the roses said.
And he was overcome with sadness. His flower had told him that she was the only one of her kind in all the universe. And here were five thousand of them, all alike, in one single garden!
"She would be very much annoyed," he said to himself, "if she should see that... she would cough most dreadfully, and she would pretend that she was dying, to avoid being laughed at. And I should be obliged to pretend that I was nursing her back to life-- for if I did not do that, to humble myself also, she would really allow herself to die..."
Then he went on with his reflections: "I thought that I was rich, with a flower that was unique in all the world; and all I had was a common rose. A common rose, and three volcanoes that come up to my knees-- and one of them perhaps extinct forever... that doesn't make me a very great prince..."
And he lay down in the grass and cried.


Assume the garden of roses has $n$ rows of roses, where there are $n$ roses in each row, aligned in a square. Initially, each rose has a color(color of the petals, of course!). The rose in the $i$-th row and $j$-th column is colored with $c_{ij}$.(There are surely colorful roses! Why would people only think of red ones when it comes to roses?)

When little prince wanders in the garden of roses, he will burst into tears when he sees two roses with the same color in the same row or the same column, as that would remind him his flower is not unique in this world.

You, a kind person, definitely don't want to see the little prince cry. Fortunately, you arrived at the garden of roses just before the little prince. You have a magic painter that could paint the stems of some roses into different colors(You don't want to ruin the petals of the roses, do you?). Initially, the stems of all roses are green. You want to paint the stems of some roses into different colors, such that no two roses in the same row or column would no longer have both the same color of petals and stems. The only problem is the number of pigments with distinct colors you need to prepare. As preparing pigments with distinct colors is time-consuming, you want to use as little pigments as possible. Please find a way to paint the flowers such that the condition is satisfied. As long as the number of pigments is minimized, any valid way of painting flowers would be considered correct.
输入解释
The first line contains a number $T(1\leq T\leq 100)$, denoting the number of test cases.
The first line of each test case contains an integer $n(1\leq n\leq 300)$, denoting the size of the garden.
Then $n$ lines follow, the $i$th$(1\leq i\leq n$) of the $n$ lines contain $n$ integers $c_{i1},c_{i2},\dots,c_{in}$, where $c_{ij}(1\leq i,j\leq n,1\leq c_{ij}\leq n^2)$ denotes the color of the rose in the $i$th row and $j$th column.

It is guaranteed that at most $10$ cases $n>20$ and at most $4$ cases $n>100$.
输出解释
For each test case, output two integers $d,m(0\leq d\leq n^2,1\leq m\leq n^2)$ in the first line, denoting the number of distinct pigments used and the number of roses to be painted.
For the next $m$ lines, output three integers $i,j,c(1\leq i,j\leq n,1\leq c\leq d)$ in a line, denoting that you would paint the stem of the rose in the $i$th row and $j$th column into color $c$. If the stem of some rose is not painted, it is regarded to have color 0.
As long as the number of pigments is minimized, any valid way of painting the stems of the roses would be considered correct.
输入样例
3
3
1 1 1
1 1 1
1 1 1
3
1 2 1
2 1 2
1 2 1
3
1 2 3
4 5 6
7 8 9
输出样例
2 6
1 2 2
1 3 1
2 1 1
2 3 2
3 1 2
3 2 1
1 4
1 3 1
3 1 1
2 3 1
3 2 1
0 0

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7074

最后修改于 2021-10-23T19:11:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000/1500MS(Java/Others) 262144/262144K(Java/Others)