编程介的小学生 2017-12-03 16:46 采纳率: 20.5%
浏览 951
已采纳

Brute Force?

Problem Description
Brute force may refer to any of several problem-solving methods involving the evaluation of multiple (or every) possible answer(s) for fitness. There is a very familiar brute-force problem for you.
There is an N * M grid, some are black while some are white. As iSea loves white more than black, he tries to change the color of all grids into white. Each time, he can choose one grid, and then the grid and its four adjacent grids will flip its color, that is, white to black, or black to white.
To make things worse, some grids are broken, and iSea can't change color on this grid, but he can change its color with its unbroken adjacent grids. Is this task possible for him?

Input
The first line contains a single integer T, indicating the number of test cases.
Each test case includes three integers N, M, K, K means the number of broken grids. Then N lines following, each line contains a string only contains 'B' or 'W', 'B' indicates black grid, 'W' indicates white grid.
Then K lines following, each line contains two integers Xi, Yi (1-based), means grid (Xi, Yi) is broken.

Technical Specification
1. 1 <= T <= 64
2. 1 <= N, M, K <= 256
3. 1 <= Xi <= N, 1 <= Yi <= M, no grid appears more than once.

Output
For each test case, output the case number first, if possible, output "Yes", otherwise output "No" (without quote).

Sample Input
3
2 2 0
BW
BB
2 2 1
BW
BW
2 1
4 3 2
WBW
BBB
WBW
WWW
2 2
3 2

Sample Output
Case 1: Yes
Case 2: Yes
Case 3: No

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-12-09 15:31
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!