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 ...
随机推荐
- 第11月第21天 php引用 codeigniter cakephp
1. class CI_Controller { private static $instance; /** * Constructor */ public function __construct( ...
- rsync更改端口后的同步办法
rsync有两种常用的认证方式,一种为rsync-daemon方式,另外一种则是ssh. 在一些场合,使用rsync-daemon方式会比较缺乏灵活性,ssh方式则成为首选.但是今天实际操作的时候发现 ...
- rstful登陆认证并检查session是否过期
一:restful用户视图 #!/usr/bin/env python # -*- coding:UTF-8 -*- # Author:Leslie-x from users import model ...
- 记关于webpack4下css提取打包去重复的那些事
注意使用vue-cli3(webpack4),默认小于30k不会抽取为公共文件,包括css和js,已测试 经过2天的填坑,现在终于有点成果 环境webpack4.6 + html-webpack-pl ...
- elasticsearch常见异常及解决办法
报错信息:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 20602552 ...
- 拓展中国剩余定理(exCRT)摘要
清除一个误区 虽然中国剩余定理和拓展中国剩余定理只差两个字,但他俩的解法相差十万八千里,所以会不会CRT无所谓 用途 求类似$$\begin{cases}x \equiv b_{1}\pmod{a_{ ...
- ASP .Net Core系统部署到SUSE Linux Enterprise Server 12 SP3 64 具体方案
.Net Core 部署到 SUSE Linux Enterprise Server 12 SP3 64 位中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2. ...
- vector的reserve和resize(转)
转自:http://www.cnblogs.com/qlee/archive/2011/05/16/2048026.html vector 的reserve增加了vector的capacity,但是它 ...
- JS实现文本中查找并替换字符
JS实现文本中查找并替换字符 效果图: 代码如下,复制即可使用: <!DOCTYPE html><html> <head> <style type=" ...
- java 捕获所有异常
1.) 通过捕获异常类型的基类Exception就可以处理所有类型的异常.(事实上还有其它的基类,但Exception是同编程活动相关的基类) 2.)因为Exception是与编程有关的所有异常类的基 ...