Cod sursa(job #1335523)

Utilizator GinguIonutGinguIonut GinguIonut Data 5 februarie 2015 17:27:01
Problema Problema Damelor Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int v[14],nr,cond1,cond2,k,i,n,ok;
int main()
{
    fin>>n;
    k=1;
    v[k]=0;
    while(k>0)
    {
        do
        {
            if(v[k]<n)
            {
                v[k]++;
                cond1=cond2=1;
                for(i=1;i<k;i++)
                {
                    if(v[i]==v[k]||v[i]-v[k]==k-i||v[k]-v[i]==k-i)
                        cond1=0;
                }
            }
            else
                cond2=0;
        }
        while(!cond1&&cond2);
            if(cond2)
                if(k==n)
                {
                    nr++;
                    if(ok==0)
                    {
                        ok=1;
                        for(i=1;i<=n;i++)
                            fout<<v[i]<<" ";
                        fout<<'\n';
                    }
                }
                else
                    v[++k]=0;
            else
                k--;
    }
    fout<<nr;
    return 0;
}