Pagini recente » Cod sursa (job #3204483) | Cod sursa (job #949685) | Cod sursa (job #1098298) | Cod sursa (job #117269) | Cod sursa (job #2770778)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("dame.in");
ofstream fout("dame.out");
vector<pair<int, int> > afis;
const int NMAX(1005);
bool mat[NMAX][NMAX], lib2[NMAX], lib[NMAX];
int n;
void mark(int x, int y)
{
int cx = x, cy = y;
while(cx <= n && cy <= n)
mat[cx][cy] = 1, ++cx, ++cy;
cx = x, cy = y;
while(cx >= 1 && cy >= 1)
mat[cx][cy] = 1, --cx, --cy;
cx = x, cy = y;
while(cx <= n && cy >= 1)
mat[cx][cy] = 1, ++cx, --cy;
cx = x, cy = y;
while(cx >= 1 && cy <= n)
mat[cx][cy] = 1, --cx, ++cy;
}
int main()
{
fin >> n;
int i, j;
if(n % 2 == 1)
i = n, j = 1;
else i = n - 1, j = 1;
afis.push_back({i, j});
mark(i, j);
lib2[i] = 1;
lib[j] = 1;
while(i != 1)
{
i -= 2;
j++;
afis.push_back({i, j});
mark(i, j);
lib[j] = 1;
lib2[i] = 1;
}
for(int x = n; x >= 1; --x)
if(!lib2[x])
{
int y = j;
while(y <= n && (lib[y] == 1 || mat[x][y] == 1))
++y;
if(y <= n)
{
lib[y] = 1;
afis.push_back({x, y});
}
}
fout << afis.size() << '\n';
for(auto it: afis)
fout << it.first << ' ' << it.second << '\n';
return 0;
}