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,如果可以操作 ,则输出最小的操作次数。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值