您的位置:首页 > 其它

usaco 2.2 runround 2008.6.20

2016-02-05 11:10 423 查看
usaco 2.2 runround 2008.6.20

{简单的模拟,循环不要错了即可}

{

ID:

PROG: runround

LANG: PASCAL

}

program p_runround;

const r:array['1'..'9']oflongint=(1,2,3,4,5,6,7,8,9);

var

f1,f2:text;

a:array['0'..'9']oflongint;

k,b:array[1..9]of longint;

c:string;l,m:longint;

flag:boolean;

procedure change;

var i:longint;

begin

for i:=1 to l do

b[i]:=r[c[i]];

end;

function choose(t:longint):boolean;

var i:longint;ch:char;

begin

fillchar(a,sizeof(a),0);str(t,c);l:=length(c);

fori:=1 to l do inc(a[c[i]]);

choose:=true;if a['0']>0 then choose:=false;

forch:='1' to '9' do if a[ch]>1 then choose:=false;

end;

procedure doit;

var p:boolean;s,x,t:longint;

begin

repeat

flag:=true;

inc(m);p:=choose(m);t:=1;

writeln(m);

if p then

begin

change;fillchar(k,sizeof(k),0);

for s:=1 to l do

begin

x:=b[t];inc(k[x]);

t:=(t+x)mod l;if t=0 then t:=l;

end;{for s}

for s:=1 to 9 do if k[s]>1 then flag:=false;

if t<>1 then flag:=false;

end else flag:=false;{if p}

until flag;

writeln(f2,m);

end;{doit}

{--------------main-----------------}

begin

assign(f1,'runround.in');reset(f1);

assign(f2,'runround.out');rewrite(f2);

read(f1,m);

doit;

close(f1);close(f2);

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: