簡單 時間限制:3 s記憶體限制:256 MB

Online Judge - 10908 - Largest Square

來源代碼:UVa
Array模擬CPE一星
前往提交 ↓

Given a rectangular grid of characters you have to find out the length of a side of the largest square such that all the characters of the square are same and the center [intersecting point of the two diagonals] of the square is at location (r, c). The height and width of the grid is M and N respectively. Upper left corner and lower right corner of the grid will be denoted by (0, 0) and (M − 1, N − 1) respectively. Consider the grid of characters given below. Given the location (1, 2) the length of a side of the largest square is 3.

abbbaaaaaa
abbbaaaaaa
abbbaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaccaaaaaa
aaccaaaaaa

輸入說明

The input starts with a line containing a single integer T (< 21). This is followed by T test cases. The first line of each of them will contain three integers M, N and Q (< 21) separated by a space where M, N denotes the dimension of the grid. Next follows M lines each containing N characters. Finally, there will be Q lines each containing two integers r and c. The value of M and N will be at most 100.

輸出說明

資料格式說明

For each test case in the input produce Q + 1 lines of output. In the first line print the value of M, N and Q in that order separated by single space. In the next Q lines, output the length of a side of the largest square in the corresponding grid for each (r, c) pair in the input.

輸入輸出範例

範例 1

範例輸入
1
7 10 4
abbbaaaaaa
abbbaaaaaa
abbbaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaccaaaaaa
aaccaaaaaa
1 2
2 4
4 6
5 2
範例輸出
7 10 4
3
1
5
1

範例 2

範例輸入
1
3 5 5
aaaaa
aaaaa
aaaaa
1 2
1 0
0 2
2 4
1 1
範例輸出
3 5 5
3
1
1
1
3

範例 3

範例輸入
2
5 5 6
aaaaa
abbba
abbba
abbba
aaaaa
2 2
1 1
0 0
2 1
4 4
3 3
3 7 4
aaaaaaa
aaaAaaa
aaaaaaa
1 3
1 2
1 5
0 6
範例輸出
5 5 6
3
1
1
1
1
1
3 7 4
1
1
3
1
開啟討論
開啟紀錄

登入後即可撰寫程式、測試範例及提交解答。

登入