A. Purification

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/329/problem/A

Description

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.

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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.

Sample Input

3
.E.
E.E
.E.

Sample Output

1 1
2 2
3 3

HINT

题意

给你一个n*n的格子,你可以释放咒语,净化这一行和一列的格子

但是有一些非常邪恶的格子,你不能释放咒语,然后问你

最少释放多少次咒语,可以净化所有的格子

(注:每种格子都得净化,不管是E还是.

题解:

一定是n次,可以直接贪心的去找就好了,如果存在一行以及一列全是E的话,就输出-1

代码

#include<iostream>
#include<stdio.h>
using namespace std; string s[];
int main()
{
int n;scanf("%d",&n);
for(int i=;i<n;i++)
cin>>s[i];
int flag1,flag2;
flag1=flag2=;
for(int i=;i<n;i++)
{
flag1=;
for(int j=;j<n;j++)
{
if(s[i][j]=='.')
flag1=;
}
if(flag1)break;
}
for(int i=;i<n;i++)
{
flag2=;
for(int j=;j<n;j++)
{
if(s[j][i]=='.')
flag2=;
}
if(flag2)break;
}
if(flag1&&flag2)
{
printf("-1\n");
return ;
}
if(!flag1)
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(s[i][j]=='.')
{
printf("%d %d\n",i+,j+);
break;
}
}
}
return ;
}
if(!flag2)
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(s[j][i]=='.')
{
printf("%d %d\n",j+,i+);
break;
}
}
}
}
}

Codeforces Round #192 (Div. 1) A. Purification 贪心的更多相关文章

  1. Codeforces Round #192 (Div. 2) (329A)C.Purification

    题意: 在一个正常的点可以净化该行该列的所有细胞,判断是否可以净化所有的细胞,并且输出所选的点. 思路: 如果可以的话,一定会选n个点. 先判断每一行是否有正常细胞,然后判断每一列是否有,如果都没有肯 ...

  2. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  3. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  4. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  5. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  6. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  7. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

  8. Codeforces Round #303 (Div. 2) C. Woodcutters 贪心

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

  9. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

随机推荐

  1. Java 7爆最新漏洞,10年前的攻击手法仍有效

    英文原文:New Reflection API affected by a known 10+ years old attack 据 SECLISTS 透露,他们发现新的 Reflection API ...

  2. [转] “error LNK2019: 无法解析的外部符号”之分析

    HiLoveS原文“error LNK2019: 无法解析的外部符号”之分析 最近在用VS 2008开发,初学遇到不少问题,最头疼的问题之一就是:LNK2019. 百度一下讲的并不够全面,反正都没解决 ...

  3. PagerSlidingTabStrip 高亮选中标题

    1.选中标题后,高亮标题@Override public void onPageSelected(int position) { setSelectTextColor(position); if (d ...

  4. ie对行高line-height的诡异解释

    切 游戏页面真地是要求太精细了,做按钮的时候我犯了一个错误,居然用span的内联元素的行高和padding来控制,虽然有很多好处,但是IE对 line-height的解释导致按钮经常下边会缺一小部分, ...

  5. 【ActiveX】实现安全接口

    转自:http://www.cnblogs.com/carekee/articles/1772201.html 感谢原作者! ActiveX控件打包成cab后,在脚本中调用中时,要保证控件的安全性才能 ...

  6. JDBC获取表的主键

    JDBC获取表的主键 案例,创建订单,并根据订单号向订单明细表插入数据 sql语句: 创建两表 create table orders(  id number(4) primary key,  cus ...

  7. BS与CS的联系与区别

    C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.InFORMix或SQL Server.客户端需要安装专用的客 ...

  8. android判断当前网络状态及跳转到设置界面

    今天,想做这个跳转到网络设置界面, 刚开始用 intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); 不料老是出现settings.Wirele ...

  9. 题目1069:查找学生信息(STL的map简单应用)

    题目描述: 输入N个学生的信息,然后进行查询. 输入:                        输入的第一行为N,即学生的个数(N<=1000) 接下来的N行包括N个学生的信息,信息格式如 ...

  10. tomcat log

    $TOMCAT_HOME$/logs/ .out tomcat 启动后的输出日志 ,主要用于输出一些常规的东西,打印的info日志也会在这里输出. 修改tomcat生成的日志位置 在开发/测试环境,日 ...