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
翰林课程体验,退费流程快速投诉邮箱: yuxi@linstitute.net 沪ICP备2023009024号-1