[Logo] Mendo Judge Discussion Board - Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
Barok  XML
Forum Index » Задачи од национални натпревари
Author Message
divio



Joined: 01/02/2016 14:28:27
Messages: 5
Offline

Nekoja ideja za barok od regionalen 2014.
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;
}

 
Forum Index » Задачи од национални натпревари
Go to:   
Powered by JForum 2.1.8 © JForum Team