SGU 121 AC!

终于AC了~~~
修正了非常多的小BUG,使用随机测试非常多次,终于AC了~
从最初的100行左右,涨到了22x行~~~
新年新气象啊~
下面是验证程序~ 不过不判无解的~
const
maxn=100;

var
c,t,p,q,n:longint;
l,r:array[1..maxn,1..maxn]of longint;
d:array[1..maxn]of longint;
col:array[1..maxn,1..2]of byte;
s:string;

begin
assign(input,’sgu121.in’);reset(input);
readln(n);
for t:=1 to n do
begin
read(p);
while p<>0 do
begin
inc(d[t]);
l[t,d[t]]:=p;
read(p);
end;
end;
close(input);
p:=0;
assign(input,’sgu121.out’);reset(input);
readln(s);
if s=’No solution’ then
begin
writeln(‘Reported No solution…’);
exit;
end;
reset(input);
for t:=1 to n do
begin
read(p);c:=0;
while p<>0 do
begin
c:=c+1;
if l[t,c]=0 then
begin
writeln(‘Error:Edge not present!’);
halt(1);
end else
if r[t,l[t,c]]=0 then
begin
r[t,l[t,c]]:=p;
r[l[t,c],t]:=p;
end else
if r[t,l[t,c]]<>p then
begin
writeln(‘Error:Color Not Suit!’);
halt(2);
end;
col[t,p]:=1;
read(p);
end;
if (col[t,1]+col[t,2]<>2)and(d[t]>=2) then
begin
writeln(‘Error:Condition not furfilled!’);
halt(3);
end;
write(t,’ ‘);
end;
writeln;
close(input);
end.

下面是生成程序:
const
n=100;
fm=200;
fz=198;

var
t,p,q:longint;
l:array[1..n,1..n]of byte;

begin
randomize;
fillchar(l,sizeof(l),0);
for t:=1 to n do
for p:=t+1 to n do
begin
q:=random(fm);
if q>fz then
begin
l[t,p]:=1;
l[p,t]:=1;
end;
end;
writeln(n);
for t:=1 to n do
begin
for p:=1 to n do
if l[t,p]=1 then write(p,’ ‘);
writeln(0);
end;
end.

希望对大家有帮助~

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.