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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Not Shading

發布時間:2023/12/20 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Not Shading 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

描述:

There is a grid with?nn?rows and?mm?columns. Some cells are colored black, and the rest of the cells are colored white.

In one operation, you can select some?black?cell and do?exactly one?of the following:

  • color all cells in its row black, or
  • color all cells in its column black.

You are given two integers?rr?and?cc. Find the minimum number of operations required to make the cell in row?rr?and column?cc?black, or determine that it is impossible.

輸入:

The input consists of multiple test cases. The first line contains an integer?tt?(1≤t≤1001≤t≤100)?— the number of test cases. The description of the test cases follows.

The first line of each test case contains four integers?nn,?mm,?rr, and?cc?(1≤n,m≤501≤n,m≤50;?1≤r≤n1≤r≤n;?1≤c≤m1≤c≤m)?— the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively.

Then?nn?lines follow, each containing?mm?characters. Each of these characters is either 'B' or 'W'?— a black and a white cell, respectively.

輸出:

For each test case, if it is impossible to make the cell in row?rr?and column?cc?black, output??1?1.

Otherwise, output a single integer?— the minimum number of operations required to make the cell in row?rr?and column?cc?black.

樣例輸入:

9 3 5 1 4 WBWWW BBBWB WWBBB 4 3 2 1 BWW BBW WBB WWB 2 3 2 2 WWW WWW 2 2 1 1 WW WB 5 9 5 9 WWWWWWWWW WBWBWBBBW WBBBWWBWW WBWBWBBBW WWWWWWWWW 1 1 1 1 B 1 1 1 1 W 1 2 1 1 WB 2 1 1 1 W B

復制

樣例輸出:

1 0 -1 2 2 0 -1 1 1

復制

注釋:

The first test case is pictured below.

We can take the black cell in row?1?and column?2, and make all cells in its row black. Therefore, the cell in row?1?and column?4?will become black.

In the second test case, the cell in row?2?and column?1?is already black.

In the third test case, it is impossible to make the cell in row?2?and column?2?black.

The fourth test case is pictured below.

We can take the black cell in row?2?and column?2?and make its column black.

Then, we can take the black cell in row?1?and column?2?and make its row black.

Therefore, the cell in row?1?and column?1?will become black.

翻譯:

描述:

有一個包含n行和m列的網格。有些細胞是黑色的,其余的細胞是白色的。

在一個操作中,您可以選擇一些黑色單元格并執行以下操作之一:

將其行中的所有單元格涂成黑色,或

將其列中的所有單元格涂成黑色。

給出兩個整數r和c。找出使r行和c列中的單元格變黑所需的最小運算次數,或者確定這是不可能的。

輸入:

輸入由多個測試用例組成。第一行包含一個整數t(1)≤T≤100)-測試用例的數量。測試用例的描述如下。

每個測試用例的第一行包含四個整數n、m、r和c(1)≤n、 m≤50;?1.≤R≤N1.≤C≤m) -網格中的行數和列數,以及需要分別變黑的單元格的行數和列數。

接著是n行,每行包含m個字符。這些字符中的每一個都是“B”或“W”——分別是黑色和白色單元格。

輸出:

對于每個測試用例,如果無法使r行和c列中的單元格變為黑色,則輸出?1

樣例輸入:

9 3 5 1 4 WBWWW BBBWB WWBBB 4 3 2 1 BWW BBW WBB WWB 2 3 2 2 WWW WWW 2 2 1 1 WW WB 5 9 5 9 WWWWWWWWW WBWBWBBBW WBBBWWBWW WBWBWBBBW WWWWWWWWW 1 1 1 1 B 1 1 1 1 W 1 2 1 1 WB 2 1 1 1 W B

復制

樣例輸出:

1 0 -1 2 2 0 -1 1 1

注釋:

第一個測試用例如下圖所示。


?

我們可以取第一行和第二列中的黑色單元格,并使其行中的所有單元格都變為黑色。因此,第1行和第4列中的單元格將變為黑色。


?

在第二個測試用例中,第2行和第1列中的單元格已經是黑色的。

在第三個測試用例中,不可能使第2行和第2列中的單元格變黑。

第四個測試用例如下圖所示。


?

我們可以把第2行和第2列中的黑色單元格變成黑色。


?

然后,我們可以將第1行和第2列中的黑色單元格設為黑色。


?

因此,第1行和第1列中的單元格將變為黑色。

總結

以上是生活随笔為你收集整理的Not Shading的全部內容,希望文章能夠幫你解決所遇到的問題。

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