Problem 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.

Examples

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

Note

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:

题意:给出一张 n*n 的图,整张图需要净化,在图中 " . "代表可以净化的点,在其上可以净化这个点所在的行、列," E " 代表无法去净化的点,即无法到达,只能通过 " . " 的净化来净化,如果能净化整张图,就输出每个格子的位置,否则输出 -1

思路:

看题意比较难,但观察下面的 Note 仔细想一想并没有那么难

首先,如同样例 2,对于某一行列均是 E 的情况,那么注定无解,因此这种情况直接输出 -1 即可

其次,若是某几行全是 E,那么为不与第一种情况冲突,可以保证剩下的行有足够的 " . " 使得可覆盖全图,对于这种情况,进行构造即可,每一列都输出第一个 " . " 的位置,可保证一定能覆盖全图

然后,若是某几列全是 E,那么为不与第一种情况冲突,可以保证剩下的列有足够的 " . " 使得可覆盖全图,对于这种情况,进行构造即可,每一行都输出第一个 " . " 的位置,可保证一定能覆盖全图

对于其他的情况,一定是行、列没有全是 E 的情况,那么同样可以找每一行每一列第一个 " . " 的位置即可

最后,根据以上 4 种情况,进行暴力搜索即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define INF 0x3f3f3f3f
#define N 10001
#define LL long long
const int MOD=998244353;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
using namespace std;
char G[N][N];
int row[N],col[N];//记录每一行每一列的E的个数
int main() {int n;cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>G[i][j];bool flagRow=false;bool flagCol=false;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='E'){row[i]++;//第i行E的个数+1col[j]++;//第j列E的个数+1if(row[i]==n)flagRow=true;if(col[j]==n)flagCol=true;if(flagRow&&flagCol){//某行某列E的个数全是E的情况cout<<-1<<endl;return 0;}}}}if(flagRow){//行全是E的情况for(int j=1;j<=n;j++){for(int i=1;i<=n;i++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}else if(flagCol){//列全是E的情况for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}else{//行或列不存在全是E的情况for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}return 0;
}

Purification(CF-330C)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  4. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  5. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  6. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

  7. 软件设计师提纲+复习资料整理(上午题)

    文章目录 软件设计师考试大纲 上午题(选择题) 一.计算机组成原理 考点:CPU结构组成 考点:原码.反码.补码定点整数范围 考点:浮点数表示 考点:RISC和CISC计算机的区别 考点:奇校验与偶校 ...

  8. c性能大容量cket_5千左右预算,既轻薄(高颜值)又高性能的笔记本推荐(畅玩LOL、CF、DNF、流放之路、梦幻西游)...

    在目前笔记本制造技术中,轻薄和性能二者不可兼得,轻薄的本性能不高,高性能的太厚重, 这里推荐一些既轻薄,外观好看,同时又高性能的轻薄本. 很多轻薄本多为低压U+集成显卡,性能太弱,都不适合玩大型3D网 ...

  9. 基于矩阵分解的CF算法实现(一):(Funk SVD)LFM

    基于矩阵分解的CF算法实现(一):LFM LFM也就是前面提到的Funk SVD矩阵分解 LFM原理解析 LFM(latent factor model)隐语义模型核心思想是通过隐含特征联系用户和物品 ...

  10. 2021.5.10(cf)

    1.cf D. Maximum Sum of Products https://codeforces.com/contest/1519/problem/D 大意:给定一个数字n代表序列的长度,接下来n ...

最新文章

  1. linux sh for ls,Linux shell for while 循环
  2. cuda error invalid argument
  3. 我开发了一个对.NET程序进行瘦身的工具
  4. [JavaWeb-JavaScript]JavaScript_RegExp正则表达式对象
  5. 【Hihocoder - 1723】子树统计(线性基合并)
  6. QT学习-10/31/2012
  7. Quartz使用总结(转)
  8. 如何选择学习主流程序语言(一)
  9. 为什么人和人的差距这么大?
  10. Chrome最新版下载地址
  11. Hadoop分布式大数据平台
  12. 伤病缠身仍愿竭力而战 澳网一别穆雷何时再见?
  13. pytorch无坑超详细图文CPU版小白安装教程(配gpu版链接、conda命令教程)
  14. 从“黑五”看亚马逊海外购的变与不变
  15. ESXi 8.0 Install
  16. EasyMock 单元测试
  17. 中国百句经典名言浅译
  18. pandas用read_scv读取含英文双引号的文件
  19. Win10 桌面图标字体怎么单独换成深色,设置白色壁纸后图标字体看不见
  20. Python Pandas条件筛选功能

热门文章

  1. 过去的2018年,400000粉丝用指尖投票,选出了这10本技术书
  2. FreeRTOS源码获取
  3. 程序员必备的GitHub加速指南,真香!
  4. 紧急通知!不要在MySQL中使用UTF-8编码!!!
  5. 看完这篇垃圾回收,和面试官扯皮没问题了
  6. NoSQL架构实践(一)——以NoSQL为辅
  7. 为什么美团全面推动 K8S 落地,咬紧牙关也要搞云原生?
  8. 漫画:当程序员有了下一代.....
  9. 微信支付软件架构重构之旅
  10. 漫画:IT公司年终总结会开崩了...