题意/Description:
读入/Input:
输入文件为compe.in。文件的第一行为参赛总人数N(1<=N<=100),从第二行到第N行依次为编号1到编号N的选手的成绩,每行有8个0~100之间的整数,代表该选手的8项竞赛成绩xi1,xi2,。。。,xi8。同一行相邻两个数之间用一个空格符隔开。
输出/Output:
输出文件为compe.out。文件有N行,从第一行到第N行依次为排名第1的选手的编号,排名第2的选手的编号,...,排名第N的选手的编号。
题解/solution:
只要把那一坨公式实现,然后多关键字排序就行了。不要用快排,不稳定。
代码/Code:
var
a:array [1..1000,1..8] of longint;
avg,sumy:array[1..1000] of real;
y:array [1..1000,1..8] of real;
sum,h:array [1..1000] of longint;
n:longint;
procedure init;
var
i,j:longint;
begin
readln(n);
for i:=1 to n do
for j:=1 to 8 do
read(a[i,j]);
end;
procedure try1;
var
i,j:longint;
begin
for i:=1 to 8 do
begin
for j:=1 to n do
avg[i]:=avg[i]+a[j,i];
avg[i]:=avg[i]/n;
end;
end;
procedure try2;
var
i,j:longint;
begin
for i:=1 to n do
begin
for j:=1 to 8 do
sum[i]:=sum[i]+a[i,j];
h[i]:=i;
end;
end;
procedure try3;
var
i,j,k:longint;
t:real;
begin
for i:=1 to n do
for j:=1 to 8 do
begin
t:=0;
for k:=1 to n do
t:=t+abs(a[k,j]-avg[j]);
if t=0 then y[i,j]:=0
else y[i,j]:=(a[i,j]-avg[j])*n/t;
end;
end;
procedure try4;
var
i,j:longint;
begin
for i:=1 to n do
begin
for j:=1 to 3 do
sumy[i]:=sumy[i]+y[i,j];
for j:=4 to 8 do
sumy[i]:=sumy[i]+y[i,j]*0.8;
end;
end;
procedure main;
var
i,j,t:longint;
k:real;
begin
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if (sumy[i]<sumy[j]) or (sumy[i]=sumy[j]) and (sum[i]<sum[j]) or
(sumy[i]=sumy[j]) and(sum[i]=sum[j]) and (h[i]>h[j]) then
begin
k:=sumy[i]; sumy[i]:=sumy[j]; sumy[j]:=k;
t:=sum[i]; sum[i]:=sum[j]; sum[j]:=t;
t:=h[i]; h[i]:=h[j]; h[j]:=t;
end;
end;
end;
procedure print;
var
i:longint;
begin
for i:=1 to n do
writeln(h[i]);
end;
begin
init;
try1;
try2;
try3;
try4;
main;
print;
end.