Расстановка ферзей на доске размерности NxN

From
Alex V Breger (2:5066/196.64)
To
Max Irgiznov
Date
2002-08-29T09:57:24Z
Area
RU.ALGORITHMS
Пpивет, Max.

Wednesday August 28 2002 21:34, Max Irgiznov писал All:

 MI> Ктониьудь из знаюжего Алл делал алгоpитм/пpогу для сабжевой задачки
 MI> пpи N> 16. Также интеpесует оценка вpемени выполнения pазличных
 MI> агоpитмов, пpи  N поpядка 16-64.
 MI> В впинципе интеpесует даже нахождение пpосто числа ваpиантов без их
 MI> вывода или генеpацию пpоизвольного ваpианта по его номеpу.

--v-Run baruch.с--
int v,i,j,k,l,s,a[99];
int main()
{
    for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!
printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&++l
||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0
:++a[i])>=s*k&&++a[--i])
        ;
}
--^-Eof baruch.с--

for в оpигинале писался в одну стpоку. Взято с ioccc.org, 1990г

описание и копиpайты

--v-Run clipboard--
Best Small Program: <baruch@genius.tau.ac.il> Osovlanski & Nissenbaum

    Doron Osovlanski
    CADTECH - CAD/CAM Systems Ltd
        24 Ben-Yosef st.
        Givat-Shmuel   51905
    Israel

    Baruch Nissenbaum                  BARUCH@TAUNIVM.TAU.AC.IL
    Tel-Aviv University
    The Faculty of Engineering
    Tel-Aviv
    Israel


Judges' comments:

    Compile.  Try:

    echo 4 | baruch
    echo 7 | baruch

    This program reads an integer between 4 and 99 from the stdin.

    NOTE: The original program did not have a newline at the end of
      the file.  We added a final newline to the file to make
      unpacking easy.


Selected notes from the author:

    The goal of this work was to write a program that solves the
>    classic n-queen problem, with a board size of up to 99x99, while
    keeping the program as short as possible.

    The program finds all possibilities to place N chess queens on
    a NxN chess board so that no queen is in range of any other queen
    (not in the same column row or diagonal).  For each solution the
    chess board and the place of the queens is printed to stdout.


    This program is about as simple and as readable as possible.
    To make things even more simple we used a very limited subset of C:

         No pre-processor statements
         Only one, harmless, 'for' statement
         No ifs
         No breaks
         No cases
         No functions
         No gotos
         No structures

    In short, it contains no C language that might confuse the
    innocent reader.  :-)


    This program demonstrates the claim that in C, any program
    can be written using a single 'for' statement, as long as it is
    long enough..

The authors further note:

    For PC users:
    In order to compile the program under Turbo-C or MSC, 'int '
    should be inserted at the beginning of the program.
    For better looking results it is recommended to replace the " #Q"
    string with " \261\2".

Copyright (c) 1990, Landon Curt Noll & Larry Bassel.
All Rights Reserved.  Permission for personal, educational or non-profit use is
granted provided this this copyright and notice are included in its entirety
and remains unaltered.  All other uses must receive prior permission in writing
from both Landon Curt Noll and Larry Bassel.
--^-Eof clipboard--

 Alex
--- GoldED+1.1.4.7/W32
 * Origin: rlu#217190 (2:5066/196.64)