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 ...
随机推荐
- python 的print和特殊方法 __str__和__repr__
先提出一个疑问,为什么print函数可以直接打印参数呢?即使是数字?例如print 1,就会打印1.我们知道1的类型是整型(题外话,在python中1是常量,也是类int的对象,而java中1只是常量 ...
- 2017/05/22 java 基础 随笔
多态:一种事物多种形态 前提:1.子父类继承关系 2.方法复写.重写 3.父类引用指向子类对象 成员变量: package com.huawei; public class Demo1 { publi ...
- activiti流程跟踪图算法
流程跟踪图-推导算法 工作中使用activiti实现流程图相关业务,但是上线后遇到问题,偶尔流程图出不来.查阅了一下画流程图的实现,基本上是参见:activiti-流程图颜色变化之一篇. 核心类,参见 ...
- Webpack vs Gulp
Webpack vs Gulp 谁会被拍死在沙滩上 本文组织结构 理想的前端开发流程 Gulp 为何物 Webpack 又是从哪冒出来的 结论 文章有点长,总共 1800 字,阅读需要 18 分钟 ...
- JS的异步模式
JS的异步模式:1.回调函数:2.事件监听:3.观察者模式:4.promise对象 JavaScript语言将任务的执行模式可以分成两种:同步(Synchronous)和异步(Asychronous) ...
- Linux 安装操作系统标准
一.注意事项. 1.虚拟机安装不做过多介绍. 2.若为主机(非服务器)安装需要按照如下步骤: a.首先需要将u盘刻录pe系统然后设置开机引导为u盘启动后进入,将以前的硬盘分区全部删除. b.若主机bi ...
- Linux性能优化之内存优化(二)
前言 不知道大家看完前面一章关于CPU优化,是否受到相应的启发呢?如果遇到任何问题,可以留言和一起探讨这方面的问题.接下来我们介绍一些关于内存方面的知识.内存管理软件包括虚拟内存系统.地址转换.交换. ...
- 010 innerHtml的使用
1.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- linux 安装redis4.0
1.安装redis 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.6.tar.gz 1 2 3 4 5 6 7 8 9 ...
- js数组去重与性能分析(时间复杂度很重要)
随着js的深入和实际项目对性能的要求,算法的简单实现已经不能满足需要,在不同的应用场景下,时间复杂度很重要. 首先是创建数组与性能处理函数: // 保证时间差的明显程度,创建不同量级的数组,size为 ...