讨论 / 给我指指错
lizhixin 2008-07-30 07:28:00
点我顶贴 收藏 删除
谁给我指指错,我连样例都没过,RQ最多赏20,我也没办法:

program t2002_4;

var n,k,i,ans,j,i2,co,s:longint;

x,y,xu,yu,poto,l,r,up,down:array[0..60]of longint;

tu:array[0..60]of boolean;

begin

readln(n,k);

for i:=1 to n do readln(x[i],y[i]);

for i:=1 to n do

begin

co:=10000;

for j:=1 to n do

if not tu[j] and (x[j]<co) then

begin

co:=x[j];

k:=j;

tu[j]:=false;

end;

xu[i]:=k;

end;

{------sort-xu------------}

fillchar(tu,sizeof(tu),0);

for i:=1 to n do

begin

co:=10000;

for j:=1 to n do

if not tu[j] and (y[j]<co) then

begin

co:=y[j];

k:=j;

tu[j]:=false;

end;

yu[i]:=k;

end;

{------sort-yu------------}

case k of

1:

begin

l[1]:=10000;r[1]:=-10000;

up[1]:=-10000;down[1]:=10000;

for i:=1 to n do

begin

if x[i]>r[1] then r[1]:=x[i];

if x[i]<l[1] then l[1]:=x[i];

if y[i]>up[1] then up[1]:=y[i];

if y[i]<down[1] then down[1]:=y[i];

end;

ans:=(r[1]-l[1])*(up[1]-down[1]);

end;

2:

begin

{l->r}

ans:=1000000;

for i:=1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[xu[j]]:=1;

for j:=i+1 to n do poto[xu[j]]:=2;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

{up->down}

for i:=1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[yu[j]]:=1;

for j:=i+1 to n do poto[yu[j]]:=2;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

3:

begin

ans:=1000000;

{l--l--l}

for i:=1 to n-2 do

for i2:=i+1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[xu[j]]:=1;

for j:=i+1 to i2 do poto[xu[j]]:=2;

for j:=i2+1 to n do poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

{up--up--up}

for i:=1 to n-2 do

for i2:=i+1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[yu[j]]:=1;

for j:=i+1 to i2 do poto[yu[j]]:=2;

for j:=i2+1 to n do poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

{l,up,down}

for i:=1 to n-2 do

begin

fillchar(poto,sizeof(poto),0);

for j:=1 to i do poto[xu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[yu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{r,up,down}

for i:=n downto 3 do

begin

fillchar(poto,sizeof(poto),0);

for j:=i+1 to n do poto[xu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[yu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{up,l,r}

for i:=n downto 3 do

begin

fillchar(poto,sizeof(poto),0);

for j:=i+1 to n do poto[yu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[xu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{down,l,r}

for i:=1 to n-2 do

begin

fillchar(poto,sizeof(poto),0);

for j:=1 to i do poto[yu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[xu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

end;

end;{case}

writeln(ans);

end.

#1 lizhixin@2008-07-20 21:36:00
回复 删除
之前的程序:

1.我在SORT中把K给替换了;

2.SORT中TU[J]应是TRUE;

program t2002_4;

var n,k,k1,i,ans,j,i2,co,s:longint;

x,y,xu,yu,poto,l,r,up,down:array[0..60]of longint;

tu:array[0..60]of boolean;

begin

readln(n,k);

for i:=1 to n do readln(x[i],y[i]);

for i:=1 to n do

begin

co:=10000;

for j:=1 to n do

if not tu[j] and (x[j]<co) then

begin

co:=x[j];

k1:=j;

end;

tu[k1]:=true;

xu[i]:=k1;

end;

{------sort-xu------------}

fillchar(tu,sizeof(tu),0);

for i:=1 to n do

begin

co:=10000;

for j:=1 to n do

if not tu[j] and (y[j]<co) then

begin

co:=y[j];

k1:=j;

end;

tu[k1]:=true;

yu[i]:=k1;

end;

{------sort-yu------------}

case k of

1:

begin

l[1]:=10000;r[1]:=-10000;

up[1]:=-10000;down[1]:=10000;

for i:=1 to n do

begin

if x[i]>r[1] then r[1]:=x[i];

if x[i]<l[1] then l[1]:=x[i];

if y[i]>up[1] then up[1]:=y[i];

if y[i]<down[1] then down[1]:=y[i];

end;

ans:=(r[1]-l[1])*(up[1]-down[1]);

end;

2:

begin

{l->r}

ans:=1000000;

i:=1;

while i<=n-1 do

begin

s:=0;

while x[xu[i]]=x[xu[i+1]] do inc(i);

for j:=1 to i do poto[xu[j]]:=1;

for j:=i+1 to n do poto[xu[j]]:=2;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

begin

inc(s,(r[j]-l[j])*(up[j]-down[j]));

//writeln(l[j], ,r[j], ,up[j], ,down[j]);

end;

//writeln(s);

if s<ans then ans:=s;

inc(i);

end;

{up->down}

i:=1;

while i<=n-1 do

begin

s:=0;

while y[yu[i]]=y[yu[i+1]] do inc(i);

for j:=1 to i do poto[yu[j]]:=1;

for j:=i+1 to n do poto[yu[j]]:=2;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

begin

inc(s,(r[j]-l[j])*(up[j]-down[j]));

//writeln(l[1], ,r[1], ,up[1], ,down[1]);

end;

//writeln(s);

if s<ans then ans:=s;

inc(i);

end;

end;

3:

begin

ans:=1000000;

{l--l--l}

for i:=1 to n-2 do

for i2:=i+1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[xu[j]]:=1;

for j:=i+1 to i2 do poto[xu[j]]:=2;

for j:=i2+1 to n do poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

{up--up--up}

for i:=1 to n-2 do

for i2:=i+1 to n-1 do

begin

s:=0;

for j:=1 to i do poto[yu[j]]:=1;

for j:=i+1 to i2 do poto[yu[j]]:=2;

for j:=i2+1 to n do poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

{l,up,down}

for i:=1 to n-2 do

begin

fillchar(poto,sizeof(poto),0);

for j:=1 to i do poto[xu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[yu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{r,up,down}

for i:=n downto 3 do

begin

fillchar(poto,sizeof(poto),0);

for j:=i+1 to n do poto[xu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[yu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[yu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{up,l,r}

for i:=n downto 3 do

begin

fillchar(poto,sizeof(poto),0);

for j:=i+1 to n do poto[yu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[xu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

{down,l,r}

for i:=1 to n-2 do

begin

fillchar(poto,sizeof(poto),0);

for j:=1 to i do poto[yu[j]]:=1;

for i2:=1 to n-1 do

begin

s:=0;

for j:=1 to i2 do

if (poto[j]=0) then poto[xu[j]]:=2;

for j:=i2+1 to n do

if (poto[j]=0) then poto[xu[j]]:=3;

for j:=1 to k do

begin

l[j]:=10000;r[j]:=-10000;

up[j]:=-10000;down[j]:=10000;

end;

for j:=1 to n do

begin

if x[j]>r[poto[j]] then r[poto[j]]:=x[j];

if x[j]<l[poto[j]] then l[poto[j]]:=x[j];

if y[j]>up[poto[j]] then up[poto[j]]:=y[j];

if y[j]<down[poto[j]] then down[poto[j]]:=y[j];

end;

for j:=1 to k do

inc(s,(r[j]-l[j])*(up[j]-down[j]));

if s<ans then ans:=s;

end;

end;

end;

end;{case}

writeln(ans);

end.

现在这个程序可以AC了

不过也有不足,没有K=4的情况,而且我只在K=2时判断了矩阵们是否重叠,K=3时没有。而且还有片面的地方,比如K=2时I枚举到N-1时如果数据N-1节点和N节点的横坐标或纵坐标相等,我的程序就把它们都放一块了,就成了一个矩形了,,,

#2 Jollwish@2008-07-30 07:28:00
回复 删除
BT的超长程序啊......
查看更多回复
提交回复