日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Purification(CF-330C)

發布時間:2025/3/17 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Purification(CF-330C) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem 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.

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.

Examples

Input

3
.E.
E.E
.E.

Output

1 1
2 2
3 3

Input

3
EEE
E..
E.E

Output

-1

Input

5
EE.EE
E.EE.
E...E
.EE.E
EE.EE

Output

3 3
1 3
2 2
4 4
5 3

Note

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:

題意:給出一張 n*n?的圖,整張圖需要凈化,在圖中 " . "代表可以凈化的點,在其上可以凈化這個點所在的行、列," E " 代表無法去凈化的點,即無法到達,只能通過 " . " 的凈化來凈化,如果能凈化整張圖,就輸出每個格子的位置,否則輸出 -1?

思路:

看題意比較難,但觀察下面的 Note 仔細想一想并沒有那么難

首先,如同樣例 2,對于某一行列均是 E 的情況,那么注定無解,因此這種情況直接輸出 -1 即可

其次,若是某幾行全是 E,那么為不與第一種情況沖突,可以保證剩下的行有足夠的 " . " 使得可覆蓋全圖,對于這種情況,進行構造即可,每一列都輸出第一個 " . " 的位置,可保證一定能覆蓋全圖

然后,若是某幾列全是 E,那么為不與第一種情況沖突,可以保證剩下的列有足夠的 " . " 使得可覆蓋全圖,對于這種情況,進行構造即可,每一行都輸出第一個 " . " 的位置,可保證一定能覆蓋全圖

對于其他的情況,一定是行、列沒有全是 E 的情況,那么同樣可以找每一行每一列第一個 " . " 的位置即可

最后,根據以上 4 種情況,進行暴力搜索即可

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<deque> #include<vector> #include<set> #include<map> #define PI acos(-1.0) #define E 1e-6 #define INF 0x3f3f3f3f #define N 10001 #define LL long long const int MOD=998244353; const int dx[]={-1,1,0,0}; const int dy[]={0,0,-1,1}; using namespace std; char G[N][N]; int row[N],col[N];//記錄每一行每一列的E的個數 int main() {int n;cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>G[i][j];bool flagRow=false;bool flagCol=false;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='E'){row[i]++;//第i行E的個數+1col[j]++;//第j列E的個數+1if(row[i]==n)flagRow=true;if(col[j]==n)flagCol=true;if(flagRow&&flagCol){//某行某列E的個數全是E的情況cout<<-1<<endl;return 0;}}}}if(flagRow){//行全是E的情況for(int j=1;j<=n;j++){for(int i=1;i<=n;i++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}else if(flagCol){//列全是E的情況for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}else{//行或列不存在全是E的情況for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(G[i][j]=='.'){cout<<i<<" "<<j<<endl;break;}}}}return 0; }

?

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的Purification(CF-330C)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲天堂少妇 | 国产成人欧美一区二区三区91 | 国模av在线| 人妻一区二区三区免费 | 在线视频观看你懂得 | 久久黄色片 | 四虎影视大全 | 中日韩黄色大片 | jzzijzzij亚洲成熟少妇 | 久色电影| 三级av毛片 | 精品久久人妻av中文字幕 | 国产做爰视频免费播放 | 国产精品精品久久久 | 黄色网页免费在线观看 | 久操免费在线视频 | 好大好舒服视频 | 茄子视频A | 天天拍夜夜爽 | 久久亚洲色图 | 波多野结衣在线看 | 岛国av一区二区 | 欧美日韩高清在线 | 成av人片一区二区三区久久 | 免费黄色小视频 | 最污的网站 | 大尺度一区二区 | 人人草人人插 | 蜜臀在线观看 | 伊人青青草视频 | 精品人妻无码一区 | 欧美经典一区二区三区 | 少妇激情偷人三级 | 成人在线视频在线观看 | 天天色棕合合合合合合合 | 欧美啪视频| 亚洲自拍中文字幕 | 久久久久久久久久久久久女过产乱 | 午夜色图| 99精品欧美一区二区三区 | 成人免费毛片视频 | 激情婷婷| 国产精品二区在线 | 521a人成v香蕉网站 | 干日本少妇 | 沟厕沟厕近拍高清视频 | 黄色三级网 | 91在线无精精品入口 | 26uuu国产精品视频 | 国产精品无码成人网站视频 | 一区二区三区xxx | 在线免费观看污网站 | 久久手机视频 | 在线波多野结衣 | 日韩人妻精品一区二区 | www.haoav| 色呦呦在线看 | 精品少妇v888av | 免费av网站观看 | 日韩αv| 在线综合视频 | 中文字幕在线视频一区二区三区 | 少妇捆绑紧缚av | 免费视频精品 | 国产三级国产精品 | 黄色在线观看视频网站 | 日韩欧美成人网 | a级黄色片网站 | 欧美三级大片 | 在线免费看污网站 | 三级视频网址 | 亚洲欧美v | 超污巨黄的小短文 | 久久av高潮av无码av喷吹 | 亚洲伊人婷婷 | 神马久久精品 | 国产精品不卡在线观看 | 亚洲天天影视 | 永久免费未网 | 国产亚洲精品久久久久久打不开 | 一级做a爰片久久毛片 | 欧美污视频在线观看 | 日韩不卡一二三区 | 99性趣网| 黑人巨大av | a级黄色片| 亚洲天堂一区在线 | 国产一区二区在线播放 | 中文字幕乱码在线观看 | 欧洲亚洲综合 | 日本色综合网 | 99爱在线 | 免费高清欧美大片在线观看 | 欧美成年人视频在线观看 | 三级福利片 | 天天综合网国产 | 僵尸叔叔在线观看国语高清免费观看 | 久久久久亚洲av成人网人人网站 | 亚洲视频一二三四 |