NOI1997

T1 竞赛排名

分析:模拟

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

 1 var
 2   n,i,j,k:longint;
 3   t1:real;
 4   x,y:array[1..1000,1..9] of real;
 5   sum,sumy,s1,s2:array[1..1000] of real;
 6   sigma,avg,s:array[1..8] of real;
 7 begin
 8 assign(input,'competitionsort.in');
 9 reset(input);
10 assign(output,'competitionsort.out');
11 rewrite(output);
12   readln(n);
13   for i:=1 to n do
14    begin
15      for j:=1 to 8 do
16       begin
17         read(x[i,j]);
18         sum[i]:=sum[i]+x[i,j];
19         sigma[j]:=sigma[j]+x[i,j];
20       end;
21      readln;
22      x[i,9]:=i;
23    end;
24 
25   {for i:=1 to n do begin
26    for j:=1 to 9 do write(x[i,j]:0:0,' '); writeln; end; }
27   //for i:=1 to n do writeln(sum[i]:0:0);
28   //for i:=1 to 8 do write(sigma[i]:0:0,' ');
29 
30   for j:=1 to 8 do
31    avg[j]:=sigma[j]/n;
32  // for i:=1 to 8 do write(avg[i]:0:5,' ');
33 
34   for j:=1 to 8 do
35    for i:=1 to n do s[j]:=s[j]+abs(x[i][j]-avg[j]);
36    //for j:=1 to 8 do writeln(s[j]);
37   for i:=1 to n do
38    for j:=1 to 8 do
39     if s[j]=0 then y[i,j]:=0
40      else y[i,j]:=(x[i][j]-avg[j])/(s[j]/n);
41 
42   {for i:=1 to n do begin
43   for j:=1 to 8 do write(y[i,j]:0:5,' '); writeln; end;}
44 
45   for i:=1 to n do
46    begin
47      for k:=1 to 3 do
48       s1[i]:=s1[i]+y[i,k];
49 
50 
51      for k:=4 to 8 do
52       s2[i]:=s2[i]+y[i,k];
53 
54    end;
55    {for i:=1 to n do
56      writeln(s1[i]:0:5,' ',s2[i]:0:5); }
57   for i:=1 to n do
58    sumy[i]:=s1[i]+0.8*s2[i];
59 
60    {for i:=1 to n do
61      writeln(sumy[i]:0:5); }
62 
63   for i:=1 to n-1 do
64    begin
65      k:=i;
66      for j:=i+1 to n do
67       if (sumy[k]<sumy[j]) or
68          ((sumy[k]=sumy[j])and(sum[k]<sum[j])) or
69          ((sumy[k]=sumy[j])and(sum[k]=sum[j])and(x[k,9]>x[j,9])) then k:=j;
70      if k<>i then begin
71                     t1:=sumy[k]; sumy[k]:=sumy[i]; sumy[i]:=t1;
72                     t1:=sum[k];  sum[k]:=sum[i];   sum[i]:=t1;
73                     t1:=x[k,9];  x[k,9]:=x[i,9];   x[i,9]:=t1;
74                   end;
75    end;
76   for i:=1 to n do writeln(x[i,9]:0:0);
77 close(input);
78 close(output);
79 end.
程序初步
 1 var
 2   n,i,j,k:longint;
 3   t1:real;
 4   x,y:array[1..1000,1..9] of real;
 5   sum,sumy,s1,s2:array[1..1000] of real;
 6   sigma,avg,s:array[1..8] of real;
 7 begin
 8 assign(input,'competitionsort.in');
 9 reset(input);
10 assign(output,'competitionsort.out');
11 rewrite(output);
12   readln(n);
13   for i:=1 to n do
14    begin
15      for j:=1 to 8 do
16       begin
17         read(x[i,j]);
18         sum[i]:=sum[i]+x[i,j];
19         sigma[j]:=sigma[j]+x[i,j];
20       end;
21      readln;
22      x[i,9]:=i;
23    end;
24   for j:=1 to 8 do
25    avg[j]:=sigma[j]/n;
26   for j:=1 to 8 do
27    for i:=1 to n do s[j]:=s[j]+abs(x[i][j]-avg[j]);
28   for i:=1 to n do
29    for j:=1 to 8 do
30     if s[j]=0 then y[i,j]:=0
31      else y[i,j]:=(x[i][j]-avg[j])/(s[j]/n);
32   for i:=1 to n do
33    begin
34      for k:=1 to 3 do
35       s1[i]:=s1[i]+y[i,k];
36      for k:=4 to 8 do
37       s2[i]:=s2[i]+y[i,k];
38    end;
39   for i:=1 to n do
40    sumy[i]:=s1[i]+0.8*s2[i];
41   for i:=1 to n-1 do
42    begin
43      k:=i;
44      for j:=i+1 to n do
45       if (sumy[k]<sumy[j]) or
46          ((sumy[k]=sumy[j])and(sum[k]<sum[j])) or
47          ((sumy[k]=sumy[j])and(sum[k]=sum[j])and(x[k,9]>x[j,9])) then k:=j;
48      if k<>i then begin
49                     t1:=sumy[k]; sumy[k]:=sumy[i]; sumy[i]:=t1;
50                     t1:=sum[k];  sum[k]:=sum[i];   sum[i]:=t1;
51                     t1:=x[k,9];  x[k,9]:=x[i,9];   x[i,9]:=t1;
52                   end;
53    end;
54   for i:=1 to n do writeln(x[i,9]:0:0);
55 close(input);
56 close(output);
57 end.
我的程序

 

posted @ 2016-02-14 16:49  ZJQCation  阅读(356)  评论(0编辑  收藏  举报