Cod sursa(job #1000724)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 23 septembrie 2013 17:32:07
Problema Dame Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <iostream>
#include <fstream>

using namespace std;

const int Nmax = 1004;

int N, n, adauga = 0;
int st[Nmax];

int main()
{
    ifstream f("dame.in");
    ofstream g("dame.out");

    f >> N;

    if ( N <= 2 )
    {
        g << "1\n1 1\n";
        return 0;
    }

    if ( N == 3 )
    {
        g << "2\n1 1\n2 3\n";
        return 0;
    }

    if ( N % 12 == 3 || N % 12 == 9 )
    {
        for ( int i = 4; i <= N; i += 2 )
                st[ ++n ] = i;

        st[ ++n ] = 2;

        adauga++;
    }
    else
    {
        for ( int i = 2; i <= N; i += 2 )
                st[ ++n ] = i;

        adauga++;
    }

    if ( N % 12 == 8 )
    {
        for ( int i = 1; i <= N; i += 2 )
                st[ ++n ] = i;

        for ( int i = 1; i <= N; i += 2 )
        {
            if ( i + 2 <= N )
                    swap( st[i], st[i + 2] );
        }

        adauga++;
    }

    if ( N % 12 == 2 )
    {
        st[ ++n ] = 3;
        st[ ++n ] = 1;

        for ( int i = 7; i <= N; i += 2 )
                st[ ++n ] = i;

        st[ ++n ] = 5;

        adauga++;
    }

    if ( N % 12 == 3 || N % 12 == 9 )
    {
        for ( int i = 5; i <= N; i += 2 )
                st[ ++n ] = i;

        st[ ++n ] = 1;
        st[ ++n ] = 3;

        adauga++;
    }

    if ( adauga < 2 )
    {
        for ( int i = 1; i <= N; i += 2 )
                st[ ++n ] = i;
    }

    g << N << "\n";

    for ( int i = 1; i <= N; ++i )
            g << i << " " << st[i] << "\n";

    return 0;
}