Codeforces Round #744 (Div. 3)C. Ticks【水题】

此篇博客讲述了如何通过算法解决一个关于纸板上V形标记的问题,判断给定的黑白格子图案是否可以通过绘制特定大小的V形符号形成。作者提供了C++代码实现思路,包括逐个检查符号并维护已标记区域,以确定是否存在无法形成给定图案的情况。
摘要由CSDN通过智能技术生成

因为他V左边高度要等于右边- -最后一发A的时候,没加最高条件重判的时候wa了。。。加上就A了呜呜呜

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).

 思路:一个个符号判过去,找一个高度超过D的V就进行修改,把V的每个点都便利标记,  全图判完后,再去找有没有是*号的 但没给标记的点,如果有就是不可能构成输出no否则yes。

#include<bits/stdc++.h>
using namespace std;
struct node{
    char f;
    int list;
}s[50][50];
void fz2(int x,int y,int g){
    int a=0,b=0,x1=x,y1=y;
    while (s[x-1][y-1].f=='*'){
        x-=1,y-=1;
        a++;
    }//判V左高度 
    x=x1,y=y1;
    while (s[x-1][y+1].f=='*'){
        x-=1,y+=1;
        b++;
    }//判v的右高度
    x=x1,y=y1;
    if (a>=g&&b>=g){
        int cs=min(a,b),cs1=min(a,b);//因为要V要对称- -所以要取最小值  - -就是因为这句没加才wa的
        s[x][y].list= false;//标记起点已经走过
        while (s[x-1][y-1].f=='*'&&cs){
            s[x-1][y-1].list= false;  //标记走过的路
            x-=1,y-=1;
            cs--;
        }
        x=x1,y=y1;
        while (s[x-1][y+1].f=='*'&&cs1){
            s[x-1][y+1].list= false; //标记走过的路
            x-=1,y+=1;
            cs1--;
        }
    }
}
int main(){
    int t,n,m,g;
    cin>>t;
    while (t--){
        cin>>n>>m>>g;
        for(int i=1;i<=n;i++){
            for (int j = 1; j <=m ; j++) {
                cin>>s[i][j].f;
                if(s[i][j].f=='*')s[i][j].list= true; //标记这些路要走
                else s[i][j].list=false;
            }
        }
        for(int i=1;i<=n;i++){
            for (int j = 1; j <=m ; j++) {
                if(s[i][j].f=='*'){
                    fz2(i,j,g); //一个个便利,找v的尖尖角,然后走可以用的V
                }
            }
        }
        int flag=0;
        for(int i=1;i<=n;i++){
            for (int j = 1; j <=m ; j++) {
                if(s[i][j].list){   //如果还有没走过的路就说明这个图不可能构成
                    flag=1;
                }
            }
        }
        if (flag)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值