Pagini recente » Cod sursa (job #545333) | Cod sursa (job #240609) | Cod sursa (job #3144244) | Cod sursa (job #586141) | Cod sursa (job #1312822)
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
ifstream in("dame.in");
ofstream out("dame.out");
int main()
{
int n, st[100], i, k, j, ev, ok=1;
char a[100][100];
in>>n;
k=1;
st[k]=0;
if(n==1)
out<<1<<"\n"<<1<<" "<<1;
if(n==2)
out<<1<<"\n"<<1<<" "<<1;
if(n==3)
out<<2<<"\n"<<1<<" "<<1<<"\n"<<3<<" "<<2;
if(n>3)
out<<n<<"\n";
while(k>0 && ok==1)
{
while(st[k]<n && ok==1)
{
st[k]++;
ev=1;
for(i=1;i<=k-1;i++)
if(st[k]==st[i] || k-i==abs(st[k]-st[i])) ev=0;
if(ev==1)
if(k==n)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(j==st[i]) out<<i<<" "<<j<<"\n";
}
ok=0;
}
else
{
k++;
st[k]=0;
}
}
k--;
}
return 0;
}