5.4 CJJ的补题之Plus from Picture

描述:

You have a given picture with size w×hw×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.

输入:

The first line contains two integers hh and ww (1≤h1≤h, w≤500w≤500) — the height and width of the picture.

The ii-th of the next hh lines contains string sisi of length ww consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.

输出:

If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".

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

样例输入:

5 6
......
..*...
.****.
..*...
..*...

复制

样例输出:

YES

复制

样例输入:

3 5
..*..
****.
.*...

复制

样例输出:

NO

复制

样例输入:

7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....

复制

样例输出:

NO

复制

样例输入:

5 6
..**..
..**..
******
..**..
..**..

复制

样例输出:

NO

复制

样例输入:

3 7
.*...*.
***.***
.*...*.

复制

样例输出:

NO

复制

样例输入:

5 10
..........
..*.......
.*.******.
..*.......
..........

复制

样例输出:

NO

复制

注释:

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

In the fifth example, there are two shapes.

In the sixth example, there is an empty space inside of the shape.

题目大意:

判断一个图里面有没有唯一一个一行一列加号

解题思路:

关键点:

1. n<=500,m<=500完全可以n^2的复杂度

2. 判断这个图是不是所给要求的图很困难,但是找到一个完整的加号并且把它消掉很简单

all in all,我们就可以用n^2复杂度找到一个加号把他消掉(只消这1个),再判断就没有*就可以啦~

代码:

#include <iostream>
using namespace std;
int n, m;
const int N = 555;
char a[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void solve()
{
    int f = 0;
    //遍历图
    for (int i = 1; i < n - 1; i++)
    {
        for (int j = 1; j < m - 1; j++)
        {
            int flag = 1;
            //判断枚举的点是不是+中心
            for (int k = 0; k < 4; k++)
            {
                int xx = i + dx[k];
                int yy = j + dy[k];
                if (a[i][j] == '.')
                {
                    flag = 0;
                    break;
                }
                if (xx >= 0 && xx < n && yy >= 0 && yy < m)
                {
                    if (a[xx][yy] == '.')
                    {
                        flag = 0;
                        break;
                    }
                }
            }
            //是的话消掉这个+
            if (flag)
            {
                // cout << i << " " << j << endl;
                a[i][j] = '.';
                for (int k = 0; k < 4; k++)
                {
                    int p = 1;
                    int xx = i + dx[k] * p;
                    int yy = j + dy[k] * p;
                    while (a[xx][yy] == '*')
                    {
                        // cout << xx << " " << yy << endl;
                        a[xx][yy] = '.';
                        p++;
                        xx = i + dx[k] * p;
                        yy = j + dy[k] * p;
                    }
                }
                f = 1;
            }
            if (f)
                break;
        }
        if (f)
            break;
    }
}
int main()
{
    int F = 0;
    cin >> n >> m;
    //特判整个图里面有没有*
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
            if(a[i][j]=='*')
                F = 1;
        }
    //消+        
    solve();
    int flag = 1;
    //消完一个+之后判断还有没有*
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] == '*')
            {
                flag = 0;
                break;
            }
        }
        if (!flag)
            break;
    }
    if (flag&&F)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
cjj / t153指的是中国电商巨头拼多多的股票代码。拼多多是一家成立于2015年的电商平台,通过社交网络的方式让用户以更低的价格购买商品。拼多多的发展迅猛,成为中国市场上的一匹黑马。 拼多多的成功源于其独特的模式和定位。不同于传统电商平台的竞争方式,拼多多以“拼团”模式吸引用户,通过社交分享促进用户的参与和互动。用户可以通过拼团的方式来获得更低的价格,这种模式的先天优势使得拼多多在短时间内迅速积累了大量的用户群体。 拼多多在中国乡村市场的布局也是其取得成功的重要原因之一。拼多多主要面向第三四线城市和农村地区,这些地区的消费者的购买力有限,借助拼多多的模式可以以更低的价格购买到所需商品。此外,拼多多还充分利用了中国农村地区的集体经济特点,通过合作社等组织为农产品找到新的销售渠道,进一步加强了与农村市场的连接。 然而,拼多多的快速发展也面临一些挑战和争议。有人批评其销售的商品质量参差不齐,存在一定的风险。同时,由于拼多多过于注重市场份额的扩大,可能降低了品牌的声誉和用户体验的质量。 总而言之,cjj / t 153代表了拼多多这家在短时间内崭露头角的电商巨头。拼多多的模式和定位具有创新性,成功地实现了在中国农村市场的拓展,但也需要关注其商品质量和用户体验等问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值