Pagini recente » Cod sursa (job #1918487) | Cod sursa (job #2643389) | Cod sursa (job #100519) | Cod sursa (job #2852574) | Cod sursa (job #3339808)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream f("castel.in");
ofstream g("castel.out");
const int DMAX=100;
struct pozitie
{
short int x,y;
};
int n;
short h[DMAX+1][DMAX+1];
queue<pozitie> q;
int nrcamere, ariemax;
pozitie pff,pss,pdj;
inline bool nord(int cod)
{
return (cod&8)!=0;
}
inline bool est(int cod)
{
return (cod&4)!=0;
}
inline bool sud(int cod)
{
return (cod&2)!=0;
}
inline bool vest(int cod)
{
return (cod&1)!=0;
}
void Fill(int x, int y, int &arie)
{
int cod=h[x][y];
arie++;
h[x][y]=-1;
if(est(cod)==0 && h[x][y+1]!=-1)
{
Fill(x,y+1,arie);
}
if(sud(cod)==0 && h[x+1][y]!=-1)
{
Fill(x+1,y,arie);
}
if( est(cod) && sud(cod) )
pff={x,y};
}
void lee()
{
while(!q.empty())
{
pozitie crt=q.front();
q.pop();
int arie=0;
Fill(crt.x,crt.y,arie);
if(arie>ariemax)
{
ariemax=arie;
pss=crt;
pdj=pff;
}
}
}
int main()
{
int c,cod;
f>>c>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
f>>cod;
h[i][j]=cod;
if( vest(cod) && nord(cod) )
{
q.push( {(short)i, (short)j } );
nrcamere++;
}
}
}
switch(c)
{
case 1:
g<<nrcamere;
break;
case 2:
lee();
g<<ariemax;
break;
case 3:
lee();
g<<pss.x<<' '<<pss.y<<' '<<pdj.x<<' '<<pdj.y;
}
f.close();
g.close();
return 0;
}