Cod sursa(job #1167151)

Utilizator ionutpop118Pop Ioan Cristian ionutpop118 Data 4 aprilie 2014 14:46:03
Problema Castel Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <cstdio>
using namespace std;
vector <int> a[155];
int viz[155][155];
int v[155];
int n,m,x,y;
inline int conv1(int l,int c)
{
	return l*(m-1)+c;
}
inline void conv2(int k)
{
	x=k/m;
	y=k%m;
	if (y==0)y=m;
}
int main()
{
    int n,m,st,s;
    scanf("%d%d%d",&n,&m,&st);
    for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)
		{
			scanf("%d",&x);
			c=conv1(i,j);
			v[c]=x;
		}
	q.push(st);
	f[st]=1;
	while (!q.empty())
	{
		aux=q.front();
		conv2
		while (!a[i].empty)
		{
			q.push(a[i].front());
			a[i].pop();
		}
		s=1;
		for (register int d=1;d<=4;++d)
		{
			nx=aux.x+dx[d];
			ny=aux.y+dy[d];
			c=conv1(nx,ny);
			if (nx>=1&&nx<=n&&ny>=1&&ny<=m)
			{
				if (f[v[c]]==1&&f[c]==0)
				{
					auxn.x=nx;
					auxn.y=ny;
					q.push(auxn);
					++s;
				}
				else
					if (f[v[c]]==0&&f[c]==0&&viz[v[c]][c]==0)
					{
						a[v[c]].push_back(c)
						viz[v[c]][c]=1;
					}
			}

		}
	}
	printf("%d\n",s);
    return 0;
}