dimitar2003
Joined: 14/09/2015 22:42:45
Messages: 3
Offline
|
Resenieto mi pominuva na 19/20. Kaj mi e greskata?
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int main()
{
int l, w;
cin>>l>>w;
int n;
cin>>n;
int b;
cin>>b;
queue<int> q;
queue<int> qi;
queue<int> qj;
bool vis[l+1][w+1];
memset(vis, false, sizeof(vis));
int R[b+1], C[b+1];
for(int i=0;i<b;i++)
{
cin>>R[i]>>C[i];
R[i] -= 1;
C[i] -= 1;
qi.push(R[i]);
qj.push(C[i]);
q.push(0);
vis[R[i]][C[i]] = true;
}
int zgradi=b;
if(zgradi>=n)
{
cout<<0;
return 0;
}
while(!q.empty())
{
int tempq=q.front();
q.pop();
int tempi = qi.front();
int tempj = qj.front();
zgradi++;
if(zgradi==n)
{
cout<<tempq;
break;
}
qi.pop();
qj.pop();
if(tempi-1 >= 0 && vis[tempi-1][tempj] == false )
{
vis[tempi-1][tempj] = true;
qi.push(tempi-1);
qj.push(tempj);
q.push(tempq+1);
}
if(tempi+1 < l && vis[tempi+1][tempj] == false )
{
vis[tempi+1][tempj] = true;
qi.push(tempi+1);
qj.push(tempj);
q.push(tempq+1);
}
if(tempj-1 >= 0 && vis[tempi][tempj-1] == false )
{
vis[tempi][tempj-1] = true;
qi.push(tempi);
qj.push(tempj-1);
q.push(tempq+1);
}
if(tempj+1 < w && vis[tempi][tempj+1]==false )
{
vis[tempi][tempj+1] = true;
qi.push(tempi);
qj.push(tempj+1);
q.push(tempq+1);
}
}
return 0;
}
|