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 ...
随机推荐
- (叉积)B - Toy Storage POJ - 2398
题目链接:https://cn.vjudge.net/contest/276358#problem/B 题目大意:和上一次写叉积的题目一样,就只是线不是按照顺序给的,是乱序的,然后输出的时候是按照有三 ...
- H - Tickets dp
题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...
- 灵活、可高度自定义的——Progress进度圈、弹窗、加载进度、小菊花
DDProgressHUD的介绍 提供了四种类型的展示: 显示无限旋转的加载图(比如小菊花,可以自定义),显示文字信息.网络刷新时经常用到. 显示加载进度的动画,也可以显示文字.网络下载时用的比较多, ...
- 【源码阅读】Mimikatz相关资料
Mimikatz GitHub (源码) https://github.com/gentilkiwi/mimikatz Mimikatz GitHub Wiki (包含了一些说明文档) https:/ ...
- php中数据库连接方式pdo和mysqli对比分析
1)总的比较 PDO MySQLi 数据库支持 12种不同的数据库支持 支持MySQL API OOP OOP + 过程 Connection Easy Easy 命名参数 支持 不支持 对象映射 ...
- 揭开webRTC媒体服务器的神秘面纱——WebRTC媒体服务器&开源项目介绍
揭开webRTC媒体服务器的神秘面纱--WebRTC媒体服务器&开源项目介绍 WebRTC生态系统是非常庞大的.当我第一次尝试理解WebRTC时,网络资源之多让人难以置信.本文针对webRTC ...
- apache+php windows下配置
2014年1月9日 13:58:54 现在PHP大部分是vc9编译的,其扩展在windows下大部分也都是用vc9编译的(memcache,xdebuge...),,所以要想Apache+PHP+PH ...
- Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息
pom.xml jar 包支持 <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch& ...
- Scala 学习笔记(2)之类和对象
Scala 的类大抵和 Java 是类似的,简单的例子如下: class MyClass { var myField : Int = 0; def this(value : Int) = { this ...
- SOA并不能解决高并发事务
传统SOA架构其实无法面对高并发事务. 这种方式不适合热点资源,也就是高并发场合. 虽然乐观锁短,但是容易产生脏数据. SOA是以服务这个方式对外提供功能,我们很显然喜欢在Service中加上JTA等 ...