codeforces翻譯,Codeforces Round #192 (Div. 1) A. Purification 貪心

 2023-10-08 阅读 19 评论 0

摘要: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 ro

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.

codeforces翻譯,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.

codeforces教程、Sample Output

1 1
2 2
3 3

HINT

?

題意

給你一個n*n的格子,你可以釋放咒語,凈化這一行和一列的格子

但是有一些非常邪惡的格子,你不能釋放咒語,然后問你

最少釋放多少次咒語,可以凈化所有的格子

codeforces難度,(注:每種格子都得凈化,不管是E還是.

題解:

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

代碼

?

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

?

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/131999.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息