POJ画家问题

网友投稿 247 2022-11-29

POJ画家问题

Description

There is a square wall which is made of n*n small square bricks. Some bricks are white while some bricks are yellow. Bob is a painter and he wants to paint all the bricks yellow. But there is something wrong with Bob’s brush. Once he uses this brush to paint brick (i, j), the bricks at (i, j), (i-1, j), (i+1, j), (i, j-1) and (i, j+1) all change their color. Your task is to find the minimum number of bricks Bob should paint in order to make all the bricks yellow.

Input

The first line contains a single integer t (1 <= t <= 20) that indicates the number of test cases. Then follow the t cases. Each test case begins with a line contains an integer n (1 <= n <= 15), representing the size of wall. The next n lines represent the original wall. Each line contains n characters. The j-th character of the i-th line figures out the color of brick at position (i, j). We use a ‘w’ to express a white brick while a ‘y’ to express a yellow brick.

Output

For each case, output a line contains the minimum number of bricks Bob should paint. If Bob can’t paint all the bricks yellow, print ‘inf’.

Sample Input

2 3 yyy yyy yyy 5 Output

0 15

注意:变黄了还能变白。。。注意边界问题

#include #include int main(){ int success,i,j,t,n,step; char ch; scanf("%d",&t); while(t--){ scanf("%d",&n); char wall[n+1][n+2]; int paint[n+1][n+2]; for(i=1;i1){ paint[1][i]=0; i++; paint[1][i]++; } } for(i=1;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java数据结构专题解析之栈和队列的实现
下一篇:计算几何----判断点是否在一个矩形内
相关文章

 发表评论

暂时没有评论,来抢沙发吧~