Pagini recente » Cod sursa (job #429772) | Cod sursa (job #2667900) | Cod sursa (job #1622821) | Cod sursa (job #2205906) | Cod sursa (job #2338144)
#include <bits/stdc++.h>
#define nmax 201
#define mmax 201
using namespace std;
struct punct
{
int x, y;
};
const int di[] = {0, -1, 0, 1};
const int dj[] = {-1, 0, 1, 0};
int a[nmax][mmax], graf[nmax][mmax];
vector <int> L[101];
int n, m, k, g, o, pozx, pozy;
queue <punct> q;
punct s;
void Citire()
{
ifstream fin("date.in");
fin >> o;
fin >> n >> m;
fin >> s.x >> s.y;
fin >> k;
for(int i = 1; i <= k; i++)
{
int x, y, r;
fin >> x >> y >> r;
a[x][y] = 1;
if(r != 0)
{
a[x][y+1] = 1;
a[x][y-1] = 1;
a[x+1][y] = 1;
a[x-1][y] = 1;
if(r == 2)
{
a[x+1][y+1] = 1;
a[x+1][y-1] = 1;
a[x-1][y+1] = 1;
a[x-1][y-1] = 1;
a[x][y+2] = 1;
a[x][y-2] = 1;
a[x+2][y] = 1;
a[x-2][y] = 1;
}
}
}
int nod = 0;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
graf[i][j] = ++nod;
fin >> g;
for(int i = 1 ; i <= g ; i++)
{
int xi, xf, yi, yf;
fin >> xi >> xf >> yi >> yf;
a[xi][xf] = a[yi][yf] = -2;
L[a[xi][xf]].push_back(a[yi][yf]);
L[a[yi][yf]].push_back(a[xi][xf]);
}
for(int i = 0 ; i <= n+1 ; i++)
a[i][0] = a[i][m+1] = -1;
for(int i = 0 ; i <= m+1 ; i++)
a[0][i] = a[n+1][i] = -1;
fin.close();
}
void Lee()
{
q.push(s);
a[s.x][s.y] = 1;
while(!q.empty())
{
punct site = q.front();
q.pop();
for(int i = 0 ; i <= 3 ; i++)
{
punct dest;
dest.x = site.x + di[i];
dest.y = site.y + dj[i];
if(a[dest.x][dest.y] == 0)
{
a[dest.x][dest.y] = a[site.x][site.y] + 1;
q.push(dest);
}
else if(a[dest.x][dest.y] == -2)
{
a[dest.x][dest.y] = a[site.x][site.y] + 1;
pozx = dest.x;
pozy = dest.y;
return ;
}
}
}
}
int main()
{
Citire();
Lee();
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cout << a[i][j] << " ";
cout << endl;
}
cout << pozx << " " << pozy;
return 0;
}