Farmer John is attempting to take a photograph of his herd of cows. From past experience, he knows this particular endeavor never usually ends well.
This time, Farmer John has purchased an expensive drone in order to take an aerial photo. To make the photo look as good as possible, he wants his cows all to be facing the same direction when the photo is taken. The cows are currently arranged in anN×NN×N?grid (2≤N≤10002≤N≤1000) inside a fenced-in square pasture, for example:
RLR
RRL
LLR
Here, an 'R' means a cow facing right, and an 'L' means a cow facing left. Since the cows are packed together, Farmer John cannot walk up to an individual cow to make it turn around. All he can do is shout at any row or column of cows to turn around, causing L's to change to R's and R's to L's within the row or column in question. Farmer John can yell at?as?many rows or columns?as?he wants, even at the same row or column more than once.
As?expected, Farmer John observes that he is unable to make his cows all face one common direction. The best he can do is get all but one of the cows to face the same direction. Please determine the identity of such a cow.
INPUT FORMAT (file leftout.in):
The first line contains?NN. The next?NN?lines describe rows?1…N1…N?in the grid of cows, each containing a string of length?NN.
OUTPUT FORMAT (file leftout.out):
Print the row and column index of a cow such that if that cow were flipped, Farmer John could make all his cows face the same direction. If no such cow exists, print -1. If multiple such cows exist, print the one with the smallest row index, or if multiple such cows have the same smallest row index, print the one with the smallest column index.
SAMPLE INPUT:
3
RLR
RRL
LLR
SAMPLE OUTPUT:
1 1
In the example above, the cow in row 1, column 1 (the upper-left corner) is the offending cow, since Farmer John can shout at row 2 and column 3 to make all other cows face left, with just this cow facing right.
Problem credits: Brian Dean
中文版
Farmer John正在嘗試給他的牛群拍照。根據(jù)以往的經(jīng)驗(yàn),他知道這一工作往往結(jié)果不怎么樣。
這一次,F(xiàn)armer John購(gòu)買(mǎi)了一臺(tái)昂貴的無(wú)人機(jī),想要拍一張航拍照。為了使照片盡可能好看,他想讓他的奶牛們?cè)谂恼諘r(shí)都朝向同一個(gè)方向。奶牛們現(xiàn)在在一塊有圍欄的草地上排列成N×NN×N(2≤N≤10002≤N≤1000)的方陣,例如:
RLR
RRL
LLR
這里,字符'R'表示一頭朝右的奶牛,字符'L'表示一頭朝左的奶牛。由于奶牛們都擠在一起,F(xiàn)armer John沒(méi)辦法走到某一頭奶牛面前讓她調(diào)轉(zhuǎn)方向。他能做的只有對(duì)著某一行或某一列的奶牛喊叫讓她們調(diào)轉(zhuǎn)方向,使得被叫到的這一行或列內(nèi)的所有L變?yōu)镽,R變?yōu)長(zhǎng)。Farmer John可以對(duì)任意多的行或列發(fā)號(hào)施令,也可以對(duì)同一行或列多次發(fā)令。
就如同F(xiàn)armer John想象的,他發(fā)現(xiàn)他不可能讓他的奶牛們都朝向同一個(gè)方向。他最多能做的是讓所有奶牛中除了一頭之外都朝向相同的方向。請(qǐng)找出這樣的一頭奶牛。
輸入格式(文件名:leftout.in):
輸入的第一行包含NN。以下NN行描述了奶牛方陣的第1…N1…N行,每行包含一個(gè)長(zhǎng)度為NN的字符串。
輸出格式(文件名:leftout.out):
輸出一頭奶牛的行列坐標(biāo),滿(mǎn)足這頭奶牛被調(diào)轉(zhuǎn)方向的話(huà),F(xiàn)armer John就可以使他的所有奶牛都朝向同一個(gè)方向。如果不存在這樣的奶牛,輸出-1。如果存在多頭這樣的奶牛,輸出其中行坐標(biāo)最小的,如果多頭這樣的奶牛具有相同的行坐標(biāo),輸出其中列坐標(biāo)最小的。
輸入樣例:
3
RLR
RRL
LLR
輸出樣例:
1 1
在這個(gè)例子中,位于第1行第1列(左上角)的奶牛是那頭令人討厭的奶牛,因?yàn)镕armer John可以喊叫第2行和第3列來(lái)讓所有奶牛都面向左側(cè),只有這一頭奶牛面向右側(cè)。
供題:Brian Dean

? 2025. All Rights Reserved. 滬ICP備2023009024號(hào)-1