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正在嘗試給他的牛群拍照。根據以往的經驗,他知道這一工作往往結果不怎么樣。
這一次,Farmer John購買了一臺昂貴的無人機,想要拍一張航拍照。為了使照片盡可能好看,他想讓他的奶牛們在拍照時都朝向同一個方向。奶牛們現在在一塊有圍欄的草地上排列成N×NN×N(2≤N≤10002≤N≤1000)的方陣,例如:
RLR
RRL
LLR
這里,字符'R'表示一頭朝右的奶牛,字符'L'表示一頭朝左的奶牛。由于奶牛們都擠在一起,Farmer John沒辦法走到某一頭奶牛面前讓她調轉方向。他能做的只有對著某一行或某一列的奶牛喊叫讓她們調轉方向,使得被叫到的這一行或列內的所有L變為R,R變為L。Farmer John可以對任意多的行或列發號施令,也可以對同一行或列多次發令。
就如同Farmer John想象的,他發現他不可能讓他的奶牛們都朝向同一個方向。他最多能做的是讓所有奶牛中除了一頭之外都朝向相同的方向。請找出這樣的一頭奶牛。
輸入格式(文件名:leftout.in):
輸入的第一行包含NN。以下NN行描述了奶牛方陣的第1…N1…N行,每行包含一個長度為NN的字符串。
輸出格式(文件名:leftout.out):
輸出一頭奶牛的行列坐標,滿足這頭奶牛被調轉方向的話,Farmer John就可以使他的所有奶牛都朝向同一個方向。如果不存在這樣的奶牛,輸出-1。如果存在多頭這樣的奶牛,輸出其中行坐標最小的,如果多頭這樣的奶牛具有相同的行坐標,輸出其中列坐標最小的。
輸入樣例:
3
RLR
RRL
LLR
輸出樣例:
1 1
在這個例子中,位于第1行第1列(左上角)的奶牛是那頭令人討厭的奶牛,因為Farmer John可以喊叫第2行和第3列來讓所有奶牛都面向左側,只有這一頭奶牛面向右側。
供題:Brian Dean

? 2026. All Rights Reserved. 滬ICP備2023009024號-1