Pagini recente » Cod sursa (job #2565045) | Cod sursa (job #2960481) | Cod sursa (job #1584931)
#include <fstream>
#define POM -1
using namespace std;
ifstream cin("barbar.in");
ofstream cout("barbar.out");
const int MAX = 1005;
queue < pair<int, int> > q;
int n, m, mat[MAX][MAX], xs, ys, xf, yf;
char ch[MAX][MAX];
int dx[]={0, 0, 1, -1};
int dy[]={1, -1, 0, 0};
void lee()
{
while(!q.empty())
{
int x = q.front().fisrt;
int y = q.front().second;
q.pop();
for(int d=0; d<4; ++d)
if(mat[ x+dx[d] ][ y+dy[d] ] == )
{
mat[ x+dx[d] ][ y+dy[d] ] = mat[x][y] + 1;
q.push({x+dx[d], y+dy[d]});
}
}
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; ++i)
cin>>ch[i] + 1;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
{
if(ch[i][j] == 'I')
{
xs = i;
ys = i;
}
if(ch[i][j] == 'O')
{
xf = i;
yf = i;
}
if(ch[i][j] == 'D')
{
mat[i][j] = 1;
q.push({i, j});
}
if(ch[i][j] == '#')
mat[i][j] = POM;
}
init();
lee();
i = 0;
pas = 1<<10;
while(pas != 0)
{
if(se_poate(i+1))
i+=pas;
pas /= 2;
}
return 0;
}