2013暑假集训B组训练赛第二场 - C - Purification
2013-07-27 17:01
399 查看
C - Purification
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 329A
Description
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.
Input
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.
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 should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Sample Input
Input
Output
Input
Output
Input
Output
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 329A
Description
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.
Input
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.
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 should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Sample Input
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 4 5 3 先开一个二维数组存数据,再判断有没有十字型的,分两种情况 EEEEE E.... E.E.. E..E. 和 EEEE. E.... E.E.. E.E.. E.... 然后一个个的输出就好
#include <cstdio> int col[200]; int row[200]; char s[105][105]; int r,c; int main() { int n; while(~scanf("%d",&n)) { r=c=0; getchar(); for(int i=1; i <= n; i++) scanf("%s",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 %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 %d\n",i,j); break; } } } return 0; }
相关文章推荐
- 2013暑假集训B组训练赛第二场
- 2013暑假集训B组训练赛第二场 - A Bus Game
- 2013暑假集训B组训练赛第二场 - E Queue at the School
- 2013暑假集训B组训练赛第二场 - B - Funky Numbers
- 2013暑假集训 第二场个人赛总结
- 2013暑假集训B组训练赛第一场
- 2013暑假集训 第三场个人赛总结
- CSU-ACM暑假集训基础组训练赛(5-1) B - Problem B
- 暑假集训——个人训练赛04——E题
- 暑假集训-合训第二场
- 2013暑假集训第二天下午总结
- 暑假集训——个人训练赛04——F题
- 2013 whu暑假集训选拔#1
- 暑假集训——个人训练赛04——I题
- 2017.8.1暑假集训第二天(下午训练赛)
- 2013 whu暑假集训选拔#2
- 暑假集训第二场
- 2013 whu暑假集训选拔#3
- CSU-ACM暑假集训基础组训练赛(2) B - Problem B
- CSU-ACM暑假集训基础组训练赛(5-1) C - Problem C