T1 竞赛排名

分析:模拟

超级大模拟,太弱了,写个模拟都要2个小时。。写的又难看又麻烦。。还需努力

 var
n,i,j,k:longint;
t1:real;
x,y:array[..,..] of real;
sum,sumy,s1,s2:array[..] of real;
sigma,avg,s:array[..] of real;
begin
assign(input,'competitionsort.in');
reset(input);
assign(output,'competitionsort.out');
rewrite(output);
readln(n);
for i:= to n do
begin
for j:= to do
begin
read(x[i,j]);
sum[i]:=sum[i]+x[i,j];
sigma[j]:=sigma[j]+x[i,j];
end;
readln;
x[i,]:=i;
end; {for i:=1 to n do begin
for j:=1 to 9 do write(x[i,j]:0:0,' '); writeln; end; }
//for i:= to n do writeln(sum[i]::);
//for i:= to do write(sigma[i]::,' '); for j:= to do
avg[j]:=sigma[j]/n;
// for i:= to do write(avg[i]::,' '); for j:= to do
for i:= to n do s[j]:=s[j]+abs(x[i][j]-avg[j]);
//for j:= to do writeln(s[j]);
for i:= to n do
for j:= to do
if s[j]= then y[i,j]:=
else y[i,j]:=(x[i][j]-avg[j])/(s[j]/n); {for i:=1 to n do begin
for j:=1 to 8 do write(y[i,j]:0:5,' '); writeln; end;} for i:= to n do
begin
for k:= to do
s1[i]:=s1[i]+y[i,k]; for k:= to do
s2[i]:=s2[i]+y[i,k]; end;
{for i:=1 to n do
writeln(s1[i]:0:5,' ',s2[i]:0:5); }
for i:= to n do
sumy[i]:=s1[i]+0.8*s2[i]; {for i:=1 to n do
writeln(sumy[i]:0:5); } for i:= to n- do
begin
k:=i;
for j:=i+ to n do
if (sumy[k]<sumy[j]) or
((sumy[k]=sumy[j])and(sum[k]<sum[j])) or
((sumy[k]=sumy[j])and(sum[k]=sum[j])and(x[k,]>x[j,])) then k:=j;
if k<>i then begin
t1:=sumy[k]; sumy[k]:=sumy[i]; sumy[i]:=t1;
t1:=sum[k]; sum[k]:=sum[i]; sum[i]:=t1;
t1:=x[k,]; x[k,]:=x[i,]; x[i,]:=t1;
end;
end;
for i:= to n do writeln(x[i,]::);
close(input);
close(output);
end.

程序初步

 var
n,i,j,k:longint;
t1:real;
x,y:array[..,..] of real;
sum,sumy,s1,s2:array[..] of real;
sigma,avg,s:array[..] of real;
begin
assign(input,'competitionsort.in');
reset(input);
assign(output,'competitionsort.out');
rewrite(output);
readln(n);
for i:= to n do
begin
for j:= to do
begin
read(x[i,j]);
sum[i]:=sum[i]+x[i,j];
sigma[j]:=sigma[j]+x[i,j];
end;
readln;
x[i,]:=i;
end;
for j:= to do
avg[j]:=sigma[j]/n;
for j:= to do
for i:= to n do s[j]:=s[j]+abs(x[i][j]-avg[j]);
for i:= to n do
for j:= to do
if s[j]= then y[i,j]:=
else y[i,j]:=(x[i][j]-avg[j])/(s[j]/n);
for i:= to n do
begin
for k:= to do
s1[i]:=s1[i]+y[i,k];
for k:= to do
s2[i]:=s2[i]+y[i,k];
end;
for i:= to n do
sumy[i]:=s1[i]+0.8*s2[i];
for i:= to n- do
begin
k:=i;
for j:=i+ to n do
if (sumy[k]<sumy[j]) or
((sumy[k]=sumy[j])and(sum[k]<sum[j])) or
((sumy[k]=sumy[j])and(sum[k]=sum[j])and(x[k,]>x[j,])) then k:=j;
if k<>i then begin
t1:=sumy[k]; sumy[k]:=sumy[i]; sumy[i]:=t1;
t1:=sum[k]; sum[k]:=sum[i]; sum[i]:=t1;
t1:=x[k,]; x[k,]:=x[i,]; x[i,]:=t1;
end;
end;
for i:= to n do writeln(x[i,]::);
close(input);
close(output);
end.

我的程序

NOI1997-LMLPHP

05-13 22:13