Cod sursa(job #460820)

Utilizator crushackPopescu Silviu crushack Data 4 iunie 2010 09:32:11
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <stdio.h>
#define lung 1000

bool ap[lung*lung];
int a[lung][lung],N,K;

void citire()
{
	freopen("tablete.in","r",stdin);
	scanf("%d%d",&N,&K);
	fclose(stdin);
}

void genMat()
{
	int i,j,k,p;
	p=1;
	for (i=0;i<N;i++)
	{
		for (j=0;j<K-1;j++)
		{
			a[i][j]=p;ap[p-1]=true;
			while (ap[p-1])
				p++;
		}
		k=p;
		while (ap[k-1] || k%2)
			k++;
		a[i][j]=k;
		ap[k-1]=true;
		while (ap[p-1])
			p++;
	}
	for (i=0;i<N;i++)
		for (j=K;j<N;j++)
		{
			a[i][j]=p;ap[p-1]=true;
			while (ap[p-1] && p<=N*N)
				p++;
		}
}

void scriere()
{
	int i,j;
	freopen("tablete.out","w",stdout);
	for (i=0;i<N;i++)
	{
		for (j=0;j<N;j++)
			printf("%3d ",a[i][j]);
		printf("\n");
	}
	fclose(stdout);
}

int main()
{
	citire();
	genMat();
	scriere();
	return 0;
}