0
点赞
收藏
分享

微信扫一扫

1360E. Polygon

_LEON_ 2022-02-26 阅读 37

E. Polygon:题目

题意:在一个n*n的方块空间内,上下都有大炮,发射数量和先后由你决定。问能否得到他给的地图。
思路:如果他不是靠下边或者右边,右或者下必有一个炮弹阻挡。所以直接遍历判断就行
#include <bits/stdc++.h>
using namespace std;
int g[100][100];
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        char ch;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cin >> ch;
                g[i][j] = ch - '0';
            }
        }
        int ff = 1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (g[i][j] == 1)
                {
                    int cou = 0;
                    if (i < n - 1)
                    {
                        if (g[i + 1][j] == 1)
                            cou++;
                    }
                    else
                        cou++;
                    if (j < n - 1)
                    {
                        if (g[i][j + 1] == 1)
                            cou++;
                    }
                    else
                        cou++;
                    if (cou == 0)
                        ff = 0;
                }
            }
        }
        if (ff)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}
举报

相关推荐

0 条评论