heat @ 2015-02-15 18:37:23
var i,j,k,l,max,n:longint;
a,b,c,d,ans:array[1..1000] of longint;
begin
read(n);
for i:=1 to n do
begin
read(b[i],c[i],d[i]);
a[i]:=i;
ans[i]:=b[i]+c[i]+d[i];
end;
for i:=1 to n do
for j:=i+1 to n do
begin
if ans[i]>ans[j] then
begin
l:=ans[i];
ans[i]:=ans[j];
ans[j]:=l;
l:=a[i];
a[i]:=a[j];
a[j]:=l;
end;
if (ans[i]=ans[j])and(b[i]=b[j]) then
begin
l:=ans[i];
ans[i]:=ans[j];
ans[j]:=l;
l:=a[i];
a[i]:=a[j];
a[j]:=l;
end;
if (ans[i]=ans[j])and(a[j]<a[i])and(b[i]=b[j]) then
begin
l:=ans[i];
ans[i]:=ans[j];
ans[j]:=l;
l:=a[i];
a[i]:=a[j];
a[j]:=l;
end;
end;
for j:=n downto 1 do
begin
inc(k);
if k=6 then break;
if (j<>1) then writeln(a[j],' ',ans[j]) else write(a[j],' ',ans[j]);
end;
end.
P1093
by controlf2 @ 2015-10-18 17:01:00
你可以用快排试试,题目总会有一部分大数(为了坑人,很大很大),选排可能会爆;
by controlf2 @ 2015-10-18 17:02:29
另外加加数组范围,毕竟人家没给数据范围。
by ALLEN @ 2016-01-06 20:01:52
看看我的!
var xh:array[1..300]of record
a,b,c:longint;
zf,xha:longint;
end;
i,j,n,tmp:longint;
begin
readln(n);
for i:=1 to n do
begin
readln(xh[i].a,xh[i].b,xh[i].c);
xh[i].zf:=xh[i].a+xh[i].b+xh[i].c;
xh[i].xha:=i;
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if xh[i].zf<xh[j].zf then
begin
tmp:=xh[i].zf;
xh[i].zf:=xh[j].zf;
xh[j].zf:=tmp;
tmp:=xh[i].a;
xh[i].a:=xh[j].a;
xh[j].a:=tmp;
tmp:=xh[i].b;
xh[i].b:=xh[j].b;
xh[j].b:=tmp;
tmp:=xh[i].c;
xh[i].c:=xh[j].c;
xh[j].c:=tmp;
tmp:=xh[i].xha;
xh[i].xha:=xh[j].xha;
xh[j].xha:=tmp;
end else if xh[i].zf=xh[j].zf then
if xh[i].a<xh[j].a then
begin
tmp:=xh[i].zf;
xh[i].zf:=xh[j].zf;
xh[j].zf:=tmp;
tmp:=xh[i].a;
xh[i].a:=xh[j].a;
xh[j].a:=tmp;
tmp:=xh[i].b;
xh[i].b:=xh[j].b;
xh[j].b:=tmp;
tmp:=xh[i].c;
xh[i].c:=xh[j].c;
xh[j].c:=tmp;
tmp:=xh[i].xha;
xh[i].xha:=xh[j].xha;
xh[j].xha:=tmp;
end else if xh[i].xha>xh[j].xha then
begin
tmp:=xh[i].zf;
xh[i].zf:=xh[j].zf;
xh[j].zf:=tmp;
tmp:=xh[i].a;
xh[i].a:=xh[j].a;
xh[j].a:=tmp;
tmp:=xh[i].b;
xh[i].b:=xh[j].b;
xh[j].b:=tmp;
tmp:=xh[i].c;
xh[i].c:=xh[j].c;
xh[j].c:=tmp;
tmp:=xh[i].xha;
xh[i].xha:=xh[j].xha;
xh[j].xha:=tmp;
end;
for i:=1 to 5 do
writeln(xh[i].xha,' ',xh[i].zf);
end.
by sythello @ 2016-02-15 11:46:05
if (ans[i]=ans[j])and(b[i]=b[j]) then
这一行似乎应该改成
if (ans[i]=ans[j])and(b[i]>b[j]) then
by syh0313 @ 2016-03-04 13:25:23
选排的时候语文成绩也要交换!
by noi_sy @ 2022-10-04 14:44:39
@heat 所以这是什么语言 Python吗