Codeforces Round #644 (Div. 3) E. Polygon

題目鏈接

思路:根據題目描述,每個炮彈存在的位置必須建立在上一個基礎上(n行或者n列除外)炮彈存在的基礎是他的右邊和下面二者必須有一個存在。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
typedef pair<int,int> PII;
const int mod=1e4+7;
const int N=2e6+10;
const int inf=0x7f7f7f7f;


ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}

template <class T>
void read(T &x)
{
    char c;
    bool op = 0;
    while(c = getchar(), c < '0' || c > '9')
        if(c == '-')
            op = 1;
    x = c - '0';
    while(c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    if(op)
        x = -x;
}
template <class T>
void write(T x)
{
    if(x < 0)
        x = -x, putchar('-');
    if(x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}
int cnt=0;
int vis[N],prim[N];
int  judge(int x)
{
    for(int i=2;i<=sqrt(x);i++)
    {
        if(x%i==0) return 0;
    }
    return 1;

}

char a[100][100];

int main()
{
   SIS;
   int t;
   cin>>t;
   while(t--)
   {
       memset(a,0,sizeof a);
       int n;
      cin>>n;
      for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
          cin>>a[i][j];


        int flag=0;
      for(int i=1;i<=n-1;i++)
      {
          for(int j=1;j<=n-1;j++)
      {
          if(a[i][j]=='1')
          {
              if(a[i+1][j]=='0'&&a[i][j+1]=='0')
              {
                  flag=1;break;
              }
          }
      }
      if(flag)
        break;
      }
      if(flag)
        cout<<"NO"<<endl;
      else
        cout<<"YES"<<endl;


   }

    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章