Ilya and tic-tac-toe game (暴力,图中斜着走)
题意:
给你一张图,然后将一个空白点填充为标记点。查询有几个相连的标记点(但只能是五子棋似的相连,纵横斜)
题解:
本来想用搜索的,但是写了一半发现,只能解决油田问题的变形题,解决这个题有点困难,并不能直来直去。然后搜了一下题解,本以为是可以完善我的搜索类型题的解法,结果一看全是暴力。
在写暴力的时候,发现斜着走写起来很困难。这点注意。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<iomanip>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define ll long long
#define mod 998244353
#define INF 0x3f3f3f3f
const int MAX = 1e6;
using namespace std;
int n,m;
char mp[6][6];
bool check()
{
for(int i=0; i<4; i++)
for(int j=0; j<2; j++)
if(mp[i][j] == 'x' && mp[i][j+1] == 'x' && mp[i][j+2] == 'x')
return 1;
for(int j=0; j<4; j++)
for(int i=0; i<2; i++)
if(mp[i][j] == 'x' && mp[i+1][j] == 'x' && mp[i+2][j] == 'x')
return 1;
for(int i=0; i<2; i++)
for(int j=0; j<2; j++)
if(mp[i][j] == 'x' && mp[i+1][j+1] == 'x' && mp[i+2][j+2] == 'x')
return 1;
for(int i=0; i<2; i++)
for(int j=2; j<4; j++)
if(mp[i][j] == 'x' && mp[i+1][j-1] == 'x' && mp[i+2][j-2] == 'x')
return 1;
return 0;
}
int main(void)
{
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
cin>>mp[i][j];
int flag = 0;
for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
if(mp[i][j] == '.')
{
mp[i][j] = 'x';
if(check())
{
flag = 1;
cout<<"YES"<<endl;
break;
}
mp[i][j] = '.';
}
}
if(flag == 1)
break;
}
if(flag == 0)
cout<<"NO"<<endl;
return 0;
}