其他分享
首页 > 其他分享> > C. Ticks

C. Ticks

作者:互联网

Problem - C - Codeforces

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.

img

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.

思路

从后枚举每个点,记录每个点能够处于最大点V,然后判断是否合法就行。

参考代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#define x first
#define y second
using namespace std;
const int MAXN = 122;
int n, m, ok;
string mp[MAXN];
int vis[MAXN][MAXN];
void cal(int i, int j)
{
	int h= 0;
	vector<pair<int, int>> ve;
	for (int r = 0; i - r >= 0 && j - h >= 0 && j + h < m; r++)
	{
		if (mp[i - r][j - h] == mp[i - r][j + h] && mp[i - r][j - h] == '*') ve.push_back({ r,h }),h++;
		else break;
	}
	for (auto it : ve) {
		int &l = vis[i - it.x][j - it.y];
		l = max(l, h - 1);
		int& r = vis[i - it.x][j + it.y];
		r = max(r, h - 1);
	}
	
}
void solve()
{
	cin >> n >> m >> ok;
	for (int i = 0; i < n; i++)cin >> mp[i];
	for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)vis[i][j] = 0;
	for(int i=n-1;i>=0;i--)
		for (int j = m - 1; j >= 0; j--)
		{
			if (mp[i][j] != '*')continue;
			cal(i, j);
			if (vis[i][j] < ok) { puts("NO"); return; }
		}
	puts("YES");
	return;
}
int main()
{
	int T; cin >> T;
	while (T--)solve();
	return 0;
}

标签:case,...,ticks,int,Ticks,field,test
来源: https://www.cnblogs.com/dabaizai/p/15365395.html