Codefoces 566 div2 B. Plus from Picture(模拟)

51 篇文章 0 订阅
33 篇文章 0 订阅

B. Plus from Picture
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a given picture with size ?×ℎ
w
×
h
. Determine if the given picture has a single “+” shape or not. A “+” shape is described below:

A “+” shape has one center nonempty cell.
There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
All other cells are empty.
Find out if the given picture has single “+” shape.

Input
The first line contains two integers ℎ
h
and ?
w
(1≤ℎ
1

h
, ?≤500
w

500
) — the height and width of the picture.

The ?
i
-th of the next ℎ
h
lines contains string ??
s
i
of length ?
w
consisting “.” and “" where “.” denotes the empty space and "” denotes the non-empty space.

Output
If the given picture satisfies all conditions, print “YES”. Otherwise, print “NO”.

You can output each letter in any case (upper or lower).

Examples
inputCopy
5 6


.
.


outputCopy
YES
inputCopy
3 5

.
.

outputCopy
NO
inputCopy
7 7


.



.*…
outputCopy
NO
inputCopy
5 6




outputCopy
NO
inputCopy
3 7
..
.
..
outputCopy
NO
inputCopy
5 10


.
.*****.


outputCopy
NO
Note
In the first example, the given picture contains one “+”.

In the second example, two vertical branches are located in a different column.

In the third example, there is a dot outside of the shape.

In the fourth example, the width of the two vertical branches is 2
2
.
In the fifth example, there are two shapes.

In the sixth example, there is an empty space inside of the shape.
题意:找到中心点,然后往四个方向标记。

#include <iostream>
#include <string>
#include <stack>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    int n, m;
    cin >> n >> m;
    int count = 0;
    vector<vector<char> > v (n);
    for (int i = 0; i < n; i++) {
        v[i].resize(m);
        for (int j = 0; j < m; j++) {
            cin >> v[i][j];
            if (v[i][j] == '*') count++;
        }
    }
    
    int x=0;
    int y=0;
    for (int i = 1; i < n-1; i++) {
        for (int j = 1; j < m-1; j++) {
            if (v[i][j] == '*' && v[i-1][j] == '*' && v[i+1][j] == '*' && v[i][j-1] == '*' && v[i][j+1] == '*') {
                x = i;
                y = j;
            }
        }
    }
    
    if (x == 0) {
        cout << "NO" << endl;
        return 0;
    }
    
    //cout << "aa " << x << " " << y << endl;
    
    for (int i = x+1; i < n; i++) {
        if (v[i][y] != '*') break;
        count--;
    }
    
    for (int i = x-1; i >= 0; i--) {
        if (v[i][y] != '*') break;
        count--;
    }
    
    for (int j = y+1; j < m; j++) {
        if (v[x][j] != '*') break;
        count--;
    }
    
    for (int j = y-1; j >= 0; j--) {
        if (v[x][j] != '*') break;
        count--;
    }
    
    if (count == 1) {
        cout << "YES" << endl;
    } else
        cout << "NO" << endl;
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值