1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include "stdafx.h"
#include <iostream>
using namespace std;
int milad(int b[10][10], int n, int m, int x1, int y1, int x2, int y2,int c[10][10])
{
if (x1 == x2 && y1 == y2)
{
return true;
}
else if (b[x1++][y1] != 1 && x1++ < n && c[x1++][y1] == 0)
{
c[x1][y1]++;
return milad(b, n, m, x1++, y1, x2, y2, c);
}
else if (b[x1--][y1] != 1 && x1-- >= 0 && c[x1--][y1] == 0)
{
c[x1][y1]++;
return milad(b, n, m, x1--, y1, x2, y2, c);
}
else if (b[x1][y1++] != 1 && y1++ < m && c[x1][y1++] == 0)
{
c[x1][y1]++;
return milad(b, n, m, x1, y1++, x2, y2, c);
}
else if (b[x1][y1--] != 1 && y1-- >= 0 && c[x1][y1--] == 0)
{
c[x1][y1]++;
return milad(b, n, m, x1, y1--, x2, y2, c);
}
return false;
}
int main()
{
char a[10][10];
int b[10][10];
int c[10][10] = {0};
int n, m, i, j;
//n * m
cin >> n >> m;
for (j = 0; j < m; j++)
{
for (i = 0; i < n; i++)
cin >> a[i][j];
}
//changing the shape to numbers
for (j = 0; j < m; j++)
{
for (i = 0; i < n; i++)
{
if (a[i][j] == '*')
b[i][j] = 1;
else b[i][j] = 0;
}
}
int x1, y1, x2, y2;
//place of entering
cin >> x1 >> y1;
//place of exiting
cin >> x2 >> y2;
i = 11, j = 11;
if (milad(b, n, m, x1, y1, x2, y2,c))
cout << "yes";
else cout << "no";
cout << endl;
system("pause");
return 0;
}
|