Pagini recente » Istoria paginii utilizator/robiarg | Profil M@2Te4i | Istoria paginii utilizator/joker_stich | Monitorul de evaluare | Cod sursa (job #206579)
Cod sursa(job #206579)
#include<stdio.h>
#include<stdlib.h>
int n,sol;
int s[1001];
void btk(){
int up,k,i,ok;
k=1;
s[k]=0;
while(k){
up=0;
while(!up&&s[k]<n){
s[k]++;
ok=1;
for(i=1;i<k&&ok;++i)
if(s[k]==s[i]||(k-i)==abs(s[k]-s[i])) ok=0;
if(ok) up=1;
}
if(up)
if(k==n) {sol=1;break;}
else k++,s[k]=0;
else k--;
}
}
int main(){
freopen("dame.in","r",stdin);
freopen("dame.out","w",stdout);
int i;
scanf("%d",&n);
btk();
if(sol){
printf("%d\n",n);
for(i=1;i<=n;++i)
printf("%d %d\n",i,s[i]);
}
return 0;
}