Cod sursa(job #296243)

Utilizator bog29Antohi Bogdan bog29 Data 4 aprilie 2009 14:59:51
Problema Tablete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<fstream.h>
ifstream in("tablete.in");
ofstream out("tablete.out");
int mat[1001][1001],n,m,r,e=0;
struct numere
{	int x,y;
};
numere nr[1000000];
int getf(int e)
{	int i;
	for(i=e;i<=n*n;i++)
		if(nr[i].y==0)
		{	e=i;
			nr[i].y=1;
			return nr[i].x;
		}
}		
int main()
{	int i,j;
	in>>n>>m;
	in.close();
	for(i=1;i<=n*n;i++)
	{	nr[i].x=i;
		nr[i].y=0;
	}	
	if(m%2==0)r=m;
	else r=m+1;
	for(i=1;i<=n;i++)
	{	mat[i][m]=(n-1)*(i-1)+r;
		nr[mat[i][m]].y=1;
	}
	for(i=1;i<=n;i++)
		for(j=1;j<m;j++)
			mat[i][j]=getf(e);	
		
	for(i=1;i<=n;i++)
		for(j=m+1;j<=n;j++)
			mat[i][j]=getf(e);	
	for(i=1;i<=n;i++)
	{	for(j=1;j<=n;j++)out<<mat[i][j]<<" ";
		out<<'\n';
	}

	out.close();
	return 0;
}