CF330 C. Purification 认真想后就成水题了
1 second
256 megabytes
standard input
standard output
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 numbered1 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.
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.
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.
3
.E.
E.E
.E.
1 1
2 2
3 3
3
EEE
E..
E.E
-1
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
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:
题解:
跟330A那题比较类似,如果你要清除一个n*n的正方形,你知道只用放n个点就能清除所有的方块。
如
*****
.....
.....
.....
.....
*的就是清除他们的点。同理竖着的,横着的,斜着的。所以我们只用构造出这样的5个点就可以了。 所以题目转换成判断是否存在这样的n个点,以及如何放的问题。
第一类:
EEEEE
E....
E....
E....
E....
这是无解的情况,因为(1,1)这个点无法清除。所以判断无解的情况只要检索是否存在一行都是E并且一列都是E这种就OK了。
第2类:
EEEEE
E....
E.E..
E..E.
.....
像这种,横着存在全是E情况的,只用在每竖行找到一个能放置的点就可以了(一定存在的,不然就是上面所说的无解情况了)。
第3类:
EEEE.
E....
E.E..
E.E..
E....
这种类似于第2类分析。每个横行找到一个能放置的点就可以了(一定存在的,不然就是上面所说的无解情况了)。
如果是 第4类这样的
EEEE.
E....
E....
E....
.....
可以直接用第2类的构造方法来做。所以这样就成了水题一道了。
/*
* @author ipqhjjybj
* @date 20130720
*
*/
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
#define ll long 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];//列
int row[200];//行 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 %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;
}
CF330 C. Purification 认真想后就成水题了的更多相关文章
- impala 四舍五入后转换成string后又变成一个double的数值解决(除不尽的情况)
impala 四舍五入后转换成string后又变成一个double的数值解决(除不尽的情况)例如Query: select cast(round(2 / 3, 4)*100 as string)+-- ...
- URAL 1136 Parliament 二叉树水题 BST后序遍历建树
二叉树水题,特别是昨天刚做完二叉树用中序后序建树,现在来做这个很快的. 跟昨天那题差不多,BST后序遍历的特型,找到最后那个数就是根,向前找,比它小的那块就是他的左儿子,比它大的那块就是右儿子,然后递 ...
- 【BZOJ】初级水题列表——献给那些想要进军BZOJ的OIers(自用,怕荒废了最后的六月考试月,刷刷水题,水水更健康)
BZOJ初级水题列表——献给那些想要进军BZOJ的OIers 代码长度解释一切! 注:以下代码描述均为C++ RunID User Problem Result Memory Time Code_Le ...
- eclipse — 导入android项目后识别成java项目的问题及解决
最近在eclipse导入android项目的时候遇到了奇葩问题,再此记录 遇到的问题就是:将完好的android项目导入到eclipse的时候,原本这是一个很容易的事情,但是导入成功后发现,,,靠ec ...
- postgresql9.5 run 文件linux安装后配置成开机服务
网上出现的比较多安装方法要么是源码安装,要么是yum安装,我发觉都要配置很多属性,比较麻烦,所以现在我在centos7长用 run文件来安装 http://get.enterprisedb.com/p ...
- 将 PDF 论文的公式截图后转成 Word 可编辑公式(23)
1. 问题 如何将PDF论文的公式截图后直接转成Word可编辑的公式? 2. 方法步骤 1.下载mathpix 2.使用mathpix截取公式,并生成LATEX 公式: 3.下载LaTeX转Word插 ...
- 从数据库读取数据后显示成html标签
也许很多人从数据库中读的数据是不需要数据成html标签的,但是也许有一天你们会发现当我们需要输出成html标签时编译器却自动帮我们输出成字符串了这是我们可以这样来 方法1: 最常用的方法,使用JS或J ...
- spyder在编辑过程中被自己弄乱了,想要恢复成安装时默认的格式或者重置页面格式的解决办法
打开spyder,tools-->Reset Spyder to factory defaults,按照如上操作即可恢复成安装时的默认格式.
- idea maven项目要想正常编译成war包,需要做的处理
以及右键项目 - Build(第一次打包成war) (第一次Build) - ReBuild(非第一次打包成war)(非第一次Build) 按照顺序做一到几次,就可以成功编译成war包了(如果rebu ...
随机推荐
- 第7月第26天 iOS httpserver
1. cocoahttpserver 1)httpserver [httpServer start:&error] 2)HTTPConnection [newConnection start] ...
- Insert Interval & Merge Intervals
Insert Intervals Given a non-overlapping interval list which is sorted by start point. Insert a new ...
- [转]html网页 swf播放器使用代码
<object id="player" height="240" width="275" classid="CLSID:6B ...
- Linux:安装mysql
#install mysql$ rpm -ivh MySQL-client-5.5.28-1.rhel5.x86_64.rpm --nodeps$ rpm -ivh MySQL-server-5.5. ...
- LINUX下IDEA等工具调试项目时提示:Unable to open debugger port
在Ubuntu下调试项目时使用TOMCAT容器,在设置好相应的TOMCAT LOCAL 路径及相关信息后,点击调试项目出现: Unable to open debugger port : java.n ...
- python基础-pthon
1)python 由Guido开发 2)编译(compile)型:通过编译器把代码直接生成一个可执行文件. 比如把英语书一次性翻译成中文书.语言有:c,C++等 解释型:边编译边执行.语言如:java ...
- SOA 设计的 9 大原则
面向服务的架构 (SOA) 设计要尽可能地简单.在设计一个 SOA 服务的时候要谨记这 9 大设计原则: 1. 标准服务契约 服务要遵循一个服务描述. 2. 松耦合 服务之间的依赖最小化. 3. 服务 ...
- php常用的安全过滤函数
目录结构 ①常用的安全函数有哪些: ②这些函数的作用: ③函数的用法: ④举例说明: ⑤参考资料: 由于越来越多的项目开始使用框架,所以,很多的程序员也不在关心安全的问题!因为框架已经帮我们几乎完美的 ...
- vuex 的使用
用于多组件共享状态,如果不打算开发大型单页应用,使用 Vuex 可能是繁琐冗余的.确实是如此——如果应用够简单,您最好不要使用 Vuex.可使用简单Bus总线的方式来管理共享的数据详见(http:// ...
- Java编程的逻辑 (65) - 线程的基本概念
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...