Bismillahir Rahmanir Rahim
When find the sign(*) just travarse all its up,down,both side & 4 courner
neighbour and checked weather a L shape is formed or not.
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int xxz[]= {-1,-1,-1,0,0,1,1,1};
int yyz[]= {-1,0,1,-1,1,-1,0,1};
bool vis[55][55];
string str[55];
bool chk(ll ki,ll kj,ll n,ll m)
{
ll arr_x=0,arr_y=0,pos=1;
for(ll i=0; i<8; i++)
{
ll new_x=xxz[i]+ki;
ll new_y=yyz[i]+kj;
if(vis[new_x][new_y]==false && (new_x>=0 && new_x<n) && (new_y>=0 && new_y<m))
{
pos++;
arr_x+=xxz[i];
arr_y+=yyz[i];
}
}
if(pos==3 && arr_x!=0 && arr_y!=0)
return true;
else
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll tst,n,m;
cin>>tst;
while(tst--)
{
bool flag=true;
cin>>n>>m;
for(ll i=0; i<n; i++)
cin>>str[i];
for(ll i=0; i<n; i++)
for(ll j=0; j<m; j++)
{
if(str[i][j]=='.')
vis[i][j]=true;
else
vis[i][j]=false;
}
for(ll i=0; i<n; i++)
for(ll j=0; j<m; j++)
if(str[i][j]=='*' && flag==true)
flag=chk(i,j,n,m);
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
///Alhamdulillah
Problem Link: https://codeforces.com/problemset/problem/1722/F
Comments
Post a Comment