CF329A.Purification

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

The cleaning of all evil will awaken the door!

Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.

The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.

You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.

Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

你是一名正在邪恶神庙中冒险的探险者。在击败了几只弱小的僵尸后,你来到了一间正方形房间,房间地面由瓷砖铺成一个 n×nn \times n 的网格。行从上到下编号为 11 至 nn,列从左到右编号为 11 至 nn。房间尽头有一扇门,被邪恶的魔法力量锁住。门上刻着如下铭文:

清除全部邪恶,方能唤醒此门!

作为一名经验极其丰富的探险者,你立刻明白了其含义。你注意到网格中的每个格子初始状态均为“邪恶”,你需要将所有这些格子全部“净化”。

目前你所知的唯一净化瓷砖的方法是施放“净化”法术。你对该法术施放于某一个格子——随后,与该格子处于同一行的所有格子,以及与该格子处于同一列的所有格子,都将被净化(包括该格子本身)!允许对同一个格子多次净化。

你希望以最少的施法次数净化全部 n×nn \times n 个格子。这听起来非常简单,但你刚刚注意到:某些格子比其他格子更加邪恶。你不能对这些格外邪恶的格子施放“净化”法术——即使它们已被净化过,依然禁止施法。不过,若某个格外邪恶的格子所在行或所在列的其他格子被选中施法,则该格外邪恶的格子仍可被间接净化。

请找出一种用最少施法次数净化所有格子的方法;若不存在这样的方法,请输出 -1。

输入格式

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。随后是 nn 行,每行包含 nn 个字符。第 ii 行的第 jj 个字符表示位于第 ii 行、第 jj 列的格子。若该格子是一个特别邪恶的格子,则该字符为 'E';否则为 '.'。

输出格式

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

如果不存在净化所有单元格的方法,则输出 -1。否则,若你的解决方案施放了 xx 次“净化”法术(其中 xx 是可能的最少法术次数),则输出 xx 行。每行应包含两个整数,表示你应施放“净化”法术的单元格的行号和列号。

输入输出样例

  • 输入#1

    3
    .E.
    E.E
    .E.

    输出#1

    1 1
    2 2
    3 3
  • 输入#2

    3
    EEE
    E..
    E.E

    输出#2

    -1
  • 输入#3

    5
    EE.EE
    E.EE.
    E...E
    .EE.E
    EE.EE

    输出#3

    3 3
    1 3
    2 2
    4 4
    5 3

说明/提示

The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.

In the second example, it is impossible to purify the cell located at row 1 and column 1.

For the third example:

第一个示例图示如下:紫色方块为尚未净化的邪恶方块;红色方块为施放“净化”法术的位置;黄色方块为当前“净化”法术所净化的方块;绿色方块为此前已被净化的方块。

在第二个示例中,位于第 1 行第 1 列的方块无法被净化。

第三个示例:

输入解题思路,AI测评打分。不知道怎么写?

首页