1.链接地址:

http://bailian.openjudge.cn/practice/2790/

2.题目:

3.思路:广搜,注意起点和终点如果不通则直接为NO

4.代码:

 #include <iostream>
#include <cstdio>
#include <queue> using namespace std; struct POINT
{
int x;
int y;
}; int idx_x[] = {-,,,};
int idx_y[] = {,,,-}; int main()
{
//freopen("C://input.txt","r",stdin); int i,j; int k;
cin >> k; while(k--)
{
int n;
cin >> n; bool **arr = new bool*[n];
for(i = ; i < n; ++i) arr[i] = new bool[n]; char ch;
for(i = ; i < n; ++i)
{
for(j = ; j < n; ++j)
{
cin >> ch;
if(ch == '.') arr[i][j] = true;
else arr[i][j] = false;
}
} int ha,la,hb,lb;
cin >> ha >> la >> hb >> lb; if(arr[ha][la] == false || arr[hb][lb] == false) {cout << "NO" << endl; continue;}
queue<POINT> q_point;
POINT point;
point.x = la;
point.y = ha;
q_point.push(point);
arr[point.y][point.x] = false; bool flag = false;
while(!q_point.empty())
{
point = q_point.front();
q_point.pop();
for(i = ; i < ; ++i)
{
POINT p2;
p2.x = point.x + idx_x[i];
p2.y = point.y + idx_y[i]; if(p2.y == hb && p2.x == lb) {flag = true;break;}
else if(p2.x >= && p2.x < n && p2.y >= && p2.y < n && arr[p2.y][p2.x])
{
q_point.push(p2);
arr[p2.y][p2.x] = false;
}
}
if(i < ) break;
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl; for(i = ; i < n; ++i) delete [] arr[i];
delete [] arr;
} return ;
}
04-18 17:38