1.29我的第十二篇
作者:互联网
题目链接:https://acs.jxnu.edu.cn/contest/23/board/challenge/A
题目: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.
我的翻译:
有一个n*m大小的矩阵,里面有n*m个方格,方格的颜色只有黑和白两种。判断需要经过几次操作是否能将指定的方格涂层黑色。以下有两种操作:只能将含有黑色的方格所在行或者所在列都涂成黑色。
输入:第一行输入一个整数 t ,代表接下来有 t 组矩阵。第二行输入 n,m,c,r。表示矩阵的大小以及需要被涂成黑色方格的坐标。
输出:如果不需要操作 则输出 0,如果不能操作,则输出 -1,如果可以操作 ,则输出最小的操作次数。
标签:第十二,rr,cc,cell,column,1.29,black,row 来源: https://blog.csdn.net/WycRs/article/details/122747168