Pagini recente » Cod sursa (job #1663785) | Cod sursa (job #2267418) | Cod sursa (job #1709206) | Cod sursa (job #1207601) | Cod sursa (job #231029)
Cod sursa(job #231029)
#include <fstream>
#include <iostream>
#include <bitset>
using namespace std;
const char iname[] = "tablete.in";
const char oname[] = "tablete.out";
#define MAXN 1005
#define FOR(i, a, b) for (int i = (a); i < (b); ++ i)
bitset <1000005> used;
int M[MAXN][MAXN]; // 4 MB
int eval(const int N, const int K)
{
used.reset();
int wrong = false;
FOR (i, 0, N) {
FOR (j, 0, N) {
if (j > 0) if (M[i][j - 1] >= M[i][j])
wrong = true;
used[ M[i][j] ] = true;
}
if (M[i][K - 1] & 1)
wrong = true;
}
FOR (i, 0, N * N) if (!used[i + 1])
wrong = true;
return (wrong == false);
}
int main(void)
{
ifstream in(iname);
int N, K;
in >> N >> K;
int cnt = 0, num = 0;
FOR (i, 0, N) {
while (cnt < K || (num & 1)) {
num ++, cnt ++;
}
cnt --;
used[num] = true;
cnt -= (K - 1);
M[i][K - 1] = num;
}
cnt = 0, num = 0;
FOR (i, 0, N) FOR (j, 0, K - 1) {
if (used[++ num]) ++ num;
M[i][j] = num;
}
FOR (i, 0, N) FOR (j, K, N) {
if (used[++ num]) ++ num;
M[i][j] = num;
}
ofstream out(oname);
FOR (i, 0, N) {
FOR (j, 0, N)
out << M[i][j] << " ";
out << "\n";
}
in.close(), out.close();
return 0;
}