(* Generazione input per "Appiattisci" (IOI 1999) Copyright (C) 2000 Paolo Boldi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) program Gen9922; {$R+} const DEBUG=false; maxp=200; type stato=array [1..maxp] of longint; var p: byte; (* Numero pile *) media: longint; (* Media input *) mosse: word; (* Numero di mosse *) stin: stato; (* Stato corrente *) seed: longint; (* Seme di generazione *) nomefile: string; (* Nome file da generare *) procedure inp; begin write('Nome file da generare: '); readln(nomefile); write('Seme (0=timer): '); readln(seed); if (seed=0) then begin randomize; seed:=random(high(word)); writeln('Seme utilizzato: ',seed) end; randseed:=seed; repeat write('Numero di pile: '); readln(p); if (not (p in [1..maxp])) then writeln('Errore!') until (p in [1..maxp]); write('Numero max mosse: '); readln(mosse) end; function min(a,b: longint): longint; begin if (a0) do begin i:=1+random(p); (* Sceglie la pila *) if (i=1) and (stin[2]=0) then continue; if (i=p) and (stin[p-1]=0) then continue; if (i in [2..p-1]) and ((stin[i-1]=0) or (stin[i+1]=0)) then continue; if (i=1) then begin v:=1+random(stin[2]); stin[1]:=stin[1]+v; stin[2]:=stin[2]-v end else if (i=p) then begin v:=1+random(stin[p-1]); stin[p]:=stin[p]+v; stin[p-1]:=stin[p-1]-v end else begin v:=1+random(min(stin[i-1],stin[i+1])); stin[i]:=stin[i]+2*v; stin[i-1]:=stin[i-1]-v; stin[i+1]:=stin[i+1]-v end; write(mosse,' '); dec(mosse) end end; procedure out; var f: text; i: byte; begin assign(f,nomefile); rewrite(f); writeln(f,p); for i:=1 to p do write(f,stin[i],' '); close(f) end; begin inp; genera; out end.