C. Ticks- Codeforces Round #744 (Div. 3)

原文链接http://codeforces.com/problemset/problem/1579/C

C. Ticks

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Casimir has a rectangular piece of paper with a checkered field of size n×mn×m. Initially, all cells of the field are white.

Let us denote the cell with coordinates ii vertically and jj horizontally by (i,j)(i,j). The upper left cell will be referred to as (1,1)(1,1) and the lower right cell as (n,m)(n,m).

Casimir draws ticks of different sizes on the field. A tick of size dd (d>0d>0) with its center in cell (i,j)(i,j) is drawn as follows:

  1. First, the center cell (i,j)(i,j) is painted black.
  2. Then exactly dd cells on the top-left diagonally to the center and exactly dd cells on the top-right diagonally to the center are also painted black.
  3. That is all the cells with coordinates (i−h,j±h)(i−h,j±h) for all hh between 00 and dd are painted. In particular, a tick consists of 2d+12d+1 black cells.

An already painted cell will remain black if painted again. Below you can find an example of the 4×94×9 box, with two ticks of sizes 22 and 33.

You are given a description of a checkered field of size n×mn×m. Casimir claims that this field came about after he drew some (possibly 00) ticks on it. The ticks could be of different sizes, but the size of each tick is at least kk (that is, d≥kd≥k for all the ticks).

Determine whether this field can indeed be obtained by drawing some (possibly none) ticks of sizes d≥kd≥k or not.

Input

The first line contains an integer tt (1≤t≤1001≤t≤100) — the number test cases.

The following lines contain the descriptions of the test cases.

The first line of the test case description contains the integers nn, mm, and kk (1≤k≤n≤101≤k≤n≤10; 1≤m≤191≤m≤19) — the field size and the minimum size of the ticks that Casimir drew. The following nn lines describe the field: each line consists of mm characters either being '.' if the corresponding cell is not yet painted or '*' otherwise.

Output

Print tt lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if the given field can be obtained by drawing ticks of at least the given size and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

Example

input

Copy

8
2 3 1
*.*
...
4 9 2
*.*.*...*
.*.*...*.
..*.*.*..
.....*...
4 4 1
*.*.
****
.**.
....
5 5 1
.....
*...*
.*.*.
..*.*
...*.
5 5 2
.....
*...*
.*.*.
..*.*
...*.
4 7 1
*.....*
.....*.
..*.*..
...*...
3 3 1
***
***
***
3 5 1
*...*
.***.
.**..

output

Copy

NO
YES
YES
YES
NO
NO
NO
NO

Note

The first sample test case consists of two asterisks neither of which can be independent ticks since ticks of size 00 don't exist.

The second sample test case is already described in the statement (check the picture in the statement). This field can be obtained by drawing ticks of sizes 22 and 33, as shown in the figure.

The field in the third sample test case corresponds to three ticks of size 11. Their center cells are marked with blueblue, redred and greengreen colors:

*.*.
*****
.****.
....

The field in the fourth sample test case could have been obtained by drawing two ticks of sizes 11 and 22. Their vertices are marked below with blueblue and redred colors respectively:

.....
*...*
.*.*.
..**.*
...**.

The field in the fifth sample test case can not be obtained because k=2k=2, and the last asterisk in the fourth row from the top with coordinates (4,5)(4,5) can only be a part of a tick of size 11.

The field in the sixth sample test case can not be obtained because the top left asterisk (1,1)(1,1) can't be an independent tick, since the sizes of the ticks must be positive, and cannot be part of a tick with the center cell in the last row, since it is separated from it by a gap (a point, '.') in (2,2)(2,2).

In the seventh sample test case, similarly, the field can not be obtained by the described process because the asterisks with coordinates (1,2)(1,2) (second cell in the first row), (3,1)(3,1) and (3,3)(3,3) (leftmost and rightmost cells in the bottom) can not be parts of any ticks.

--------------------------------------------------------------------------------------------------------------------------------

现在给你一个棋盘,请问棋盘上的黑色格子是否可以由若干个大小至少为 k 的对勾图案染色而成。

本题乍一看很难,无从下手。但仔细观察,突破点在k值,要求合格的对号大小大于等于k,那么大小小于k的就 是不合格的,我们对合格的对号进行染色,枚举每一个‘*’,朝着左上右上不停扩展,直到遇到边界或者非*点终止,两边的大小可能不一样大,取最小的,那么以这个点为顶点的对号就出来了。如果大小大于等于k,再重新循环标记这些点,否则不标记。

这样,我们实际上枚举了全部情况(每个顶点都被枚举),之后还没被标记的,那肯定要输出no

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long int ll;
bool book[50][50];
char ch[50][50];
int main()
{

    int t;
    cin>>t;

    while(t--)
    {
        int n,m,k;

        cin>>n>>m>>k;

        memset(book,0,sizeof(book));
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                cin>>ch[i][j];
            }
        }

        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(ch[i][j]=='*')
                {

                    int left=0;

                    int x=i-1;
                    int y=j-1;
                //朝左上角扩展
                    while(x&&y&&ch[x][y]=='*')
                    {
                        left++;
                        x--;
                        y--;

                    }
                    x=i-1;
                    y=j+1;
                    int right=0;
                //朝右上角扩展
                
                    while(x&&y<=m&&ch[x][y]=='*')
                    {
                        right++;
                        x--;
                        y++;
                    }
                    int mid=min(left,right);
                //左右都满足的最大对号

                    if(mid>=k)  //大小适合,开始标记
                    {
                        book[i][j]=1;
                        x=i-1;
                        y=j-1;
                        left=0;
                        right=0;

                        while(x&&y&&ch[x][y]=='*'&&left<mid)
                        {
                            book[x][y]=1;
                            left++;
                            x--;
                            y--;

                        }

                        x=i-1;
                        y=j+1;


                        while(x&&y<=m&&ch[x][y]=='*'&&right<mid)
                        {
                            book[x][y]=1;
                            right++;
                            x--;
                            y++;
                        }



                    }
                }
            }
        }

        int ans=0;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(ch[i][j]=='*'&&book[i][j]==0)
                {
                    ans=1;
                    break;
                }
            }
            if(ans)
                break;
        }

        if(ans)
            cout<<"NO"<<'\n';
        else
            cout<<"YES"<<'\n';

    }

    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值