C. Purification
Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
You are an adventurer currently journeying inside an edevil temple. after defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n blocks x blocks n grid. the rows are numbered 1 through n from top to bottom, and the columns are numbered1 through n from left to right. at the far side of the room lies a door locked with edevil magical forces. the following inscriptions are written on the door:
The cleaning of all edevil 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 edevil. You showould 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 wowould like to purify all n rows × limit 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 certainly more edevil than the other tiles. you cannot cast the "Purification" spell on those participant ularly more edevil 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.
Input
The first line will contain in a single integer n (1 rows ≤ limit n rows ≤ limit 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 particle ly more edevil cell, and '. 'Otherwise.
Output
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 shoshould consist of two integers denoting the row and column numbers of the cell on which you shoshould cast the "Purification" spell.
Sample test (s)
Input
3
. E.
E. E
. E.
Output
1 1
2 2
3 3
Input
3
EEE
E ..
E. E
Output
-1
Input
5
EE. EE
E. EE.
E... E
. EE. E
EE. EE
Output
3 3
1 3
2 2
4
5 3 Note
The first example is already strated as follows. purple tiles are edevil 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 previusly.
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
Question:
Let's just look at the description of the question. Just look at the example below to explain it. That is, E cannot be placed in the clearing point.
Question:
Similar to the 330A question, if you want to clear an n * n square, you know that you can clear all squares with only n points.
For example
*****
.....
.....
.....
.....
* Is to clear their points. Similarly, vertical, horizontal, and oblique. So we only need to construct these five points. Therefore, the question is converted to the question of determining whether such n points exist and how to put them.
Category 1:
EEEEE
E ....
E ....
E ....
E ....
This is unsolvable because () cannot be cleared. Therefore, to determine whether there is no solution, it is OK as long as a row is E and A column is E.
Class 2nd:
EEEEE
E ....
E. E ..
E. E.
.....
In this case, the existence of the horizontal layout is all E. You only need to find a point that can be placed on each vertical line (it must exist, or else it is the above mentioned no solution ).
Class 3rd:
EEEE.
E ....
E. E ..
E. E ..
E ....
This type of analysis is similar to the 2nd Type Analysis. You can find a point that can be placed in a row (it must exist, otherwise it is the unsolved situation mentioned above ).
For example, for the 4th class
EEEE.
E ....
E ....
E ....
.....
You can directly use the constructor of class 2nd. So it becomes a question of water.
/** @ Author ipqhjjybj * @ date 20130720 **/# include <cstdio> # include <cstdlib> # include <algorithm> # include <iostream> # include <cstring> using namespace std; # define ll long # define max (a, B) (a)> (B )? (A) :( B) # define min (a, B) (a) <(B )? (A) :( B) # define clr (x, k) memset (x, k, sizeof (x) int col [200]; // column int row [200]; // row char s [105] [105]; int r, c; int main () {// freopen ("330C. in "," r ", stdin); int n; scanf (" % d ", & n); r = c = 0; getchar (); for (int I = 1; I <= n; I ++) gets (s [I] + 1); for (int I = 1; I <= n; I ++) for (int j = 1; j <= n; j ++) {if (s [I] [j] = 'E ') {row [I] ++, col [j] ++; if (row [I] = n) r = 1; if (col [j] = n) c = 1; if (r & c) {puts ("-1"); return 0 ;}} if (r) for (int j = 1; j <= n; j ++) {for (int I = 1; I <= n; I ++) {if (s [I] [j] = '. ') {printf ("% d \ n", I, j); break ;}} else {for (int I = 1; I <= n; I ++) for (int j = 1; j <= n; j ++) if (s [I] [j] = '. ') {printf ("% d \ n", I, j); break;} return 0 ;}