Cod sursa(job #952011)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 22 mai 2013 15:28:18
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
using namespace std;
const char iname[] = "tablete.in";
const char oname[] = "tablete.out";
ifstream fin(iname);
ofstream fout(oname);
int N, K, X, Y, i, j, lim, aux, gK;
int a[1004][1004];
int main(){
	fin >> N >> K;
	if (!(K & 1)){
		lim = K;
		for (i = 1; i <= N; ++i)
			for (j = 1; j <= lim; ++j) a[i][j] = ++X;
		for (i = 1; i <= N; ++i)
			for (j = lim + 1; j <= N; ++j) a[i][j] = ++X;
		for (i = 1; i <= N; ++i){
			for (j = 1; j <= N; ++j) fout << a[i][j] << ' ';
			fout << '\n';
		}
	}
	else{
		lim = K;
		for (i = 1; i <= N; ++i){
			if (Y) a[i][1] = Y;
			else a[i][1] = ++X;
			for (j = 2; j < lim; ++j) a[i][j] = ++X;
			Y = 0;
			if (i & 1){
				Y = X + 1;
				a[i][lim] = Y + 1; X = Y + 1;
			}
			else
				a[i][lim] = ++X;
		}
		if (Y) gK = 1;
		for (i = 1; i <= N; ++i){
			for (j = lim + 1; j <= N; ++j){
				if (gK && j == lim + 1) a[i][j] = Y, gK = 0;
				else
					a[i][j] = ++X;
			}
		}
		for (i = 1; i <= N; ++i){
			for (j = 1; j <= N; ++j) fout << a[i][j] << ' ';
			fout << '\n';
		}
	}
	return 0;
}