Cod sursa(job #2770774)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 23 august 2021 10:26:22
Problema Dame Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#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];
int n;
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});
    lib2[i] = 1;
    while(i != 1)
    {
        i -= 2;
        j++;
        afis.push_back({i, j});
        lib2[i] = 1;
    }
    for(; j <= n; ++j)
    {
        int x = n;
        while(x >= 1 && lib2[x] == 1)
            --x;
        if(x >= 1)
        {
            lib2[x] = 1;
            afis.push_back({x, j});
        }
    }
    fout << afis.size() << '\n';
    for(auto it: afis)
        fout << it.first << ' ' << it.second << '\n';
    return 0;
}