Cod sursa(job #951983)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 22 mai 2013 14:50:01
Problema Tablete Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 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;
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; Y = 1; X = 1;
		for (i = 1; i <= N; ++i){
			if (!Y) a[i][1] = ++X;
			else a[i][1] = Y;
			for (j = 2; j < lim; ++j) a[i][j] = ++X;
			aux = X + 1;
			if (!(aux & 1)) a[i][lim] = ++X, Y = 0;
			else{
				Y = ++X; ++X;
				a[i][lim] = 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';
		}
	}
	return 0;
}