Cod sursa(job #1278743)

Utilizator serbanSlincu Serban serban Data 29 noiembrie 2014 12:39:51
Problema Problema Damelor Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int n,m,x[1005],k,ok=0;

int bun(int i)
{
    int j;
    for(j=1;j<i;j++)
    {
        if(x[i]==x[j])
            return 0;
        int z1=i-j,z2=x[i]-x[j];
        if(z1<0) z1=-z1;
        if(z2<0) z2=-z2;
        if(z1==z2)
            return  0;
    }
    return 1;
}
void okay()
{
    if(!ok)
    {
        int i=1;
        for(i=1;i<=n;i++)
            cout<<x[i]<<" ";
        cout<<"\n";
        ok=1;
    }
}
int main()
{
    int i,j;
    freopen("damesah.in","r",stdin);
    freopen("damesah.out","w",stdout);
    cin>>n;
    i=1;
    while(i!=0)
    {
        while(i!=0 && i<=n)
        {
            x[i]++;
            if(x[i]>n) x[i]=0,i--;
            else if(bun(i)) i++;
        }
        if(i>n) okay(),k++,i=n;
    }
    cout<<k<<"\n";
    return 0;
}