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.
{简单的模拟,循环不要错了即可}
{
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.
相关文章推荐
- 数据库中导出表中对应字段到指定文件里
- 搭建LAMP
- 安装Linux时“分区”入门操作详解
- Android ImageView图片自适应
- 第二届蓝桥杯C/C++组第八题 三角螺旋阵
- java泛型类为什么不能声持有类型的静态变量
- 论文《FDDB: A Benchmark for Face Detection in Unconstrained Settings》导读
- usaco 2.1 frac1 2008.5.10
- usaco 2.1 sort3 2008.5.20
- usaco 2.1 holstein 2008.5.20
- PHP面向对象深入研究之【对象生成】
- 关于url路径的定义方式
- 1005 -
- wpftoolkit,好多wpf控件,有空可以用用
- 类型转换异常处理java.lang.RuntimeException
- 第4讲项目2——完成简单计算(4)
- 类型转换异常处理java.lang.RuntimeException
- 类型转换异常处理java.lang.RuntimeException
- Fedora21下安装VirtualBox及Mac虚拟机
- Swift中使用typealias定义一个闭包closure