第七个点wa了怎么办

P1093 [NOIP2007 普及组] 奖学金

linlin @ 2017-05-08 21:30:48

var n,y,s,g,z:array[1..301] of integer;
i,j,t,a:longint;
begin
read(a);
for i:=1 to a do
readln(y[i],s[i],g[i]);
for i:=1 to a do
n[i]:=i;
for i:=1 to a do
z[i]:=y[i]+s[i]+g[i];
for i:=1 to a-1 do
for j:=i+1 to a do
begin
if z[j]>z[i] then begin
t:=n[i];n[i]:=n[j];n[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=g[i];g[i]:=g[j];g[j]:=t;
t:=z[i];z[i]:=z[j];z[j]:=t;
end
else if( z[j]=z[i])and(y[j]>y[i])then begin
t:=n[i];n[i]:=n[j];n[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=g[i];g[i]:=g[j];g[j]:=t;
t:=z[i];z[i]:=z[j];z[j]:=t;
end
else if ( z[j]=z[i])and(y[j]=y[i])and((j<i)or(j>i)) then begin
t:=n[i];n[i]:=n[j];n[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=g[i];g[i]:=g[j];g[j]:=t;
t:=z[i];z[i]:=z[j];z[j]:=t;
end
end;
for i:=1 to 5 do
writeln(n[i],' ',z[i]);
end.

by linlin @ 2017-05-08 21:43:02

90分求解


by 666yuchen @ 2017-06-03 09:54:24

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a,b[305],c[305],d[305],z[305],e[305],t;
int main()
{
  scanf("%d",&a);
  for(int i=1;i<=a;i++)
  {
      scanf("%d%d%d",&b[i],&c[i],&d[i]);
      z[i]=i;
      e[i]=b[i]+c[i]+d[i];
  }
  for(int i=1;i<=a-1;i++)
    for(int j=i+1;j<=a;j++)
      if(e[i]<e[j]||e[i]==e[j]&&b[i]<b[j]||e[i]==e[j]&&b[i]==b[j]&&z[i]>z[j])
      {
        t=b[i];b[i]=b[j];b[j]=t;
        t=c[i];c[i]=c[j];c[j]=t;
        t=d[i];d[i]=d[j];d[j]=t;
        t=z[i];z[i]=z[j];z[j]=t;
        t=e[i];e[i]=e[j];e[j]=t;
      }
  for(int i=1;i<=5;i++)cout<<z[i]<<" "<<e[i]<<endl;
  return 0;
}

by 666yuchen @ 2017-06-03 09:55:02

C++满分程序


|