usaco 2.1 castle 2008.5.30
2016-02-05 11:10
453 查看
usaco 2.1 castle 2008.5.30
{
ID:
PROG: castle
LANG: PASCAL
}
program p_castle;
const
fin='castle.in';fout='castle.out';
maxn=50;
type
code1=array[1..2]of longint;
arr1=array[1..maxn,1..maxn]of integer;
arr2=array[1..maxn,1..maxn]of longint;
var
x:array[1..maxn*maxn]of code1;
a:arr1;b:arr2;f1,f2:text;
y:array[1..maxn*maxn]of longint;
i,j,x1,x2,n,m,l1,l2,max1,max2,ly,p1,p2:longint;
s,w:array[1..maxn,1..maxn]of boolean;
p3:char;
procedure init;
var i,j:longint;
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
read(f1,m,n);
for i:=1 to n do for j:=1 to m do
read(f1,a[i,j]);
end;
procedure deal;
varr,pp,i,t1,t2,p1,p2:longint;
begin
repeat
t1:=x[x1,1];t2:=x[x1,2];
pp:=15-a[t1,t2];
r:=b[t1,t2];
p1:=t1+1;p2:=t2;
if pp>=8 then
begin
dec(pp,8);
if (s[p1,p2])and(p1<=n) then
begininc(y[r]);b[p1,p2]:=r;s[p1,p2]:=false;{避免重复累计r}
if w[p1,p2] then beginw[p1,p2]:=false;x[x2,1]:=p1;x[x2,2]:=p2;inc(x2);end;
end;
end;
if pp>=4 then
begin
dec(pp,4);
if (t2+1<=m)and(s[t1,t2+1])then
begininc(y[r]);b[t1,t2+1]:=r;s[t1,t2+1]:=false;
if(w[t1,t2+1])then beginw[t1,t2+1]:=false;x[x2,1]:=t1;x[x2,2]:=t2+1;inc(x2);end;
end;
end;
if pp>=2 then
begin
dec(pp,2);
if (t1-1>0)and(s[t1-1,t2])then
begininc(y[r]);b[t1-1,t2]:=r;s[t1-1,t2]:=false;
if (w[t1-1,t2]) then beginw[t1-1,t2]:=false;x[x2,1]:=t1-1;x[x2,2]:=t2;inc(x2);end;
end;
end;
if pp>=1 then
begin
if (t2-1>0)and(s[t1,t2-1])then
begininc(y[r]);b[t1,t2-1]:=r;s[t1,t2-1]:=false;
if (w[t1,t2-1]) then beginw[t1,t2-1]:=false;x[x2,1]:=t1;x[x2,2]:=t2-1;inc(x2);end;
end;
end;
inc(x1);
until (x2=x1);
end;
procedure find;
var i,j,i1,j1:longint;
begin
for j:=1 to m do
for i:=n downto 1 do
begin
j1:=j+1;
i1:=i-1;
if(i1>0)and(b[i,j]<>b[i1,j]) then
ify[b[i,j]]+y[b[i1,j]]>max2 then
begin
max2:=y[b[i,j]]+y[b[i1,j]];
p1:=i;p2:=j;p3:='N';
end;
if (j1<=m)and(b[i,j]<>b[i,j1]) then
if y[b[i,j]]+y[b[i,j1]]>max2then
begin
max2:=y[b[i,j1]]+y[b[i,j]];
p1:=i;p2:=j;p3:='E';
end;
end;
end;
procedure doit;
vark,j:longint;
begin
fillchar(s,sizeof(s),true);
fillchar(w,sizeof(w),true);
ly:=0;
fillchar(b,sizeof(b),0);
for k:=1 to n do for j:=1 to m do
if a[k,j]=15 then
begin
inc(ly);b[k,j]:=ly;
y[ly]:=1;w[k,j]:=false;
s[k,j]:=false;
end
else
if b[k,j]=0 then
begin
inc(ly);b[k,j]:=ly;
y[ly]:=1;x1:=1;x2:=2;
x[x1,1]:=k;x[x1,2]:=j;
w[k,j]:=false;s[k,j]:=false;
deal
end;
end;
{---------------main-----------------}
begin
max1:=-1;
max2:=-1;
init;
doit;
find;
fori:=1 to ly do
if y[i]>max1 then max1:=y[i];
writeln(f2,ly);
writeln(f2,max1);
writeln(f2,max2);
writeln(f2,p1,' ',p2,' ',p3);
close(f1); close(f2);
end.
{
ID:
PROG: castle
LANG: PASCAL
}
program p_castle;
const
fin='castle.in';fout='castle.out';
maxn=50;
type
code1=array[1..2]of longint;
arr1=array[1..maxn,1..maxn]of integer;
arr2=array[1..maxn,1..maxn]of longint;
var
x:array[1..maxn*maxn]of code1;
a:arr1;b:arr2;f1,f2:text;
y:array[1..maxn*maxn]of longint;
i,j,x1,x2,n,m,l1,l2,max1,max2,ly,p1,p2:longint;
s,w:array[1..maxn,1..maxn]of boolean;
p3:char;
procedure init;
var i,j:longint;
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
read(f1,m,n);
for i:=1 to n do for j:=1 to m do
read(f1,a[i,j]);
end;
procedure deal;
varr,pp,i,t1,t2,p1,p2:longint;
begin
repeat
t1:=x[x1,1];t2:=x[x1,2];
pp:=15-a[t1,t2];
r:=b[t1,t2];
p1:=t1+1;p2:=t2;
if pp>=8 then
begin
dec(pp,8);
if (s[p1,p2])and(p1<=n) then
begininc(y[r]);b[p1,p2]:=r;s[p1,p2]:=false;{避免重复累计r}
if w[p1,p2] then beginw[p1,p2]:=false;x[x2,1]:=p1;x[x2,2]:=p2;inc(x2);end;
end;
end;
if pp>=4 then
begin
dec(pp,4);
if (t2+1<=m)and(s[t1,t2+1])then
begininc(y[r]);b[t1,t2+1]:=r;s[t1,t2+1]:=false;
if(w[t1,t2+1])then beginw[t1,t2+1]:=false;x[x2,1]:=t1;x[x2,2]:=t2+1;inc(x2);end;
end;
end;
if pp>=2 then
begin
dec(pp,2);
if (t1-1>0)and(s[t1-1,t2])then
begininc(y[r]);b[t1-1,t2]:=r;s[t1-1,t2]:=false;
if (w[t1-1,t2]) then beginw[t1-1,t2]:=false;x[x2,1]:=t1-1;x[x2,2]:=t2;inc(x2);end;
end;
end;
if pp>=1 then
begin
if (t2-1>0)and(s[t1,t2-1])then
begininc(y[r]);b[t1,t2-1]:=r;s[t1,t2-1]:=false;
if (w[t1,t2-1]) then beginw[t1,t2-1]:=false;x[x2,1]:=t1;x[x2,2]:=t2-1;inc(x2);end;
end;
end;
inc(x1);
until (x2=x1);
end;
procedure find;
var i,j,i1,j1:longint;
begin
for j:=1 to m do
for i:=n downto 1 do
begin
j1:=j+1;
i1:=i-1;
if(i1>0)and(b[i,j]<>b[i1,j]) then
ify[b[i,j]]+y[b[i1,j]]>max2 then
begin
max2:=y[b[i,j]]+y[b[i1,j]];
p1:=i;p2:=j;p3:='N';
end;
if (j1<=m)and(b[i,j]<>b[i,j1]) then
if y[b[i,j]]+y[b[i,j1]]>max2then
begin
max2:=y[b[i,j1]]+y[b[i,j]];
p1:=i;p2:=j;p3:='E';
end;
end;
end;
procedure doit;
vark,j:longint;
begin
fillchar(s,sizeof(s),true);
fillchar(w,sizeof(w),true);
ly:=0;
fillchar(b,sizeof(b),0);
for k:=1 to n do for j:=1 to m do
if a[k,j]=15 then
begin
inc(ly);b[k,j]:=ly;
y[ly]:=1;w[k,j]:=false;
s[k,j]:=false;
end
else
if b[k,j]=0 then
begin
inc(ly);b[k,j]:=ly;
y[ly]:=1;x1:=1;x2:=2;
x[x1,1]:=k;x[x1,2]:=j;
w[k,j]:=false;s[k,j]:=false;
deal
end;
end;
{---------------main-----------------}
begin
max1:=-1;
max2:=-1;
init;
doit;
find;
fori:=1 to ly do
if y[i]>max1 then max1:=y[i];
writeln(f2,ly);
writeln(f2,max1);
writeln(f2,max2);
writeln(f2,p1,' ',p2,' ',p3);
close(f1); close(f2);
end.
相关文章推荐
- usaco 2.1 hamming 2008.6.10
- usaco 2.2 runround 2008.6.20
- 数据库中导出表中对应字段到指定文件里
- 搭建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