ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CF w4d2 C. Purification

2020-05-27 22:53:33  阅读:236  来源: 互联网

标签:EE spell CF evil Purification cell w4d2 row


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

inputCopy
3
.E.
E.E
.E.
outputCopy
1 1
2 2
3 3
inputCopy
3
EEE
E..
E.E
outputCopy
-1
inputCopy
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
outputCopy
3 3
1 3
2 2
4 4
5 3

#include<bits/stdc++.h>
using namespace std;

char f[105][105];
int n,row[105],col[105];
int xmax=0,ymax=0;

int judge()
{
	int flag=1;
	for(int i=1;i<=n;i++){
		xmax=max(xmax,row[i]);
		ymax=max(ymax,col[i]);
	}	
	if(xmax==n&&ymax==n)flag=0;
	return flag;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>f[i][j];
			if(f[i][j]=='E'){
				row[i]++;
				col[j]++;
			}
		}
	}
	if(judge()==0){
		cout<<"-1"<<endl;
		return 0;
	}
	if(xmax!=n){
		for(int i=1;i<=n;i++){
			int pos=0;
			for(int j=1;j<=n;j++)if(f[i][j]=='.')pos=j;
			cout<<i<<" "<<pos<<endl;
		}
	}
	else{
		for(int i=1;i<=n;i++){
			int pos=0;
			for(int j=1;j<=n;j++)if(f[j][i]=='.')pos=j;
			cout<<pos<<" "<<i<<endl;
		}		
	}
	return 0;
}

标签:EE,spell,CF,evil,Purification,cell,w4d2,row
来源: https://www.cnblogs.com/LiangYC1021/p/12977212.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有