Cod sursa(job #1724460)

Utilizator BlackNestaAndrei Manaila BlackNesta Data 3 iulie 2016 11:52:59
Problema Problema Damelor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("damesa.in");
ofstream g("damesa.out");

vector <int> v;
int cnt, n;

inline bool  Verifica()
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            if (v[i] == v[j] || (i - j == abs(v[i] - v[j])))
                return false;
    return true;
}

int main()
{
    f >> n;
    f.close();
    for(int i = 1; i <= n; i++)
        v.push_back(i);
    while(next_permutation(v.begin(), v.end()))
    {
        if(Verifica())
        {
            if(cnt == 0 )
                for(int i = 1; i <= n; i++)
                    g << v[i] << " ";
                g << "\n";
            cnt++;
        }
    }
    return 0;
}