为什么过不了,我的代码有错吗?

测试数据 #0: WrongAnswer, time = 0 ms, mem = 936 KiB, score = 0

测试数据 #1: Accepted, time = 0 ms, mem = 936 KiB, score = 10

测试数据 #2: Accepted, time = 0 ms, mem = 932 KiB, score = 10

测试数据 #3: Accepted, time = 0 ms, mem = 936 KiB, score = 10

测试数据 #4: Accepted, time = 0 ms, mem = 940 KiB, score = 10

测试数据 #5: Accepted, time = 0 ms, mem = 932 KiB, score = 10

测试数据 #6: WrongAnswer, time = 0 ms, mem = 932 KiB, score = 0

测试数据 #7: Accepted, time = 15 ms, mem = 932 KiB, score = 10

测试数据 #8: Accepted, time = 0 ms, mem = 936 KiB, score = 10

测试数据 #9: WrongAnswer, time = 15 ms, mem = 936 KiB, score = 0

WrongAnswer, time = 30 ms, mem = 940 KiB, score = 70
代码

var

n,w,i,j,ans:longint;

a:array[0..30000]of longint;

procedure qs(head,tail:longint);

var

i,j,x,t:longint;

begin

i:=head;

j:=tail;

x:=a[(tail+head)div 2];

while i<j do
begin
while a[i]<x do
inc(i);
while a[j]>x do

dec(j);

if (i<=j) then

begin

t:=a[i];

a[i]:=a[j];

a[j]:=t;

inc(i);

dec(j);

end;

end;

if head<j
then qs(head,j);
if tail>i

then qs(i,tail);

end;

begin

readln(w);

readln(n);

for i:=1to n do

readln(a[i]);

qs(1,n);

j:=n;

i:=1;

ans:=0;

while i<j do

begin

if a[i]+a[j]<=w then

begin

i:=i+1;

j:=j-1;

inc(ans);

end

else

if (a[j]<=w) then

begin

j:=j- 1;

inc(ans);

end

else j:=j-1;

end;

writeln(ans);

end.

2 条评论

  • @ 2018-01-23 14:28:52

    那个题目上说每组最多两个纪念品不考虑这一点会错6 9 10

  • @ 2017-01-23 15:09:14

    编译成功
    Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
    Copyright (c) 1993-2015 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    Linking foo.exe
    48 lines compiled, 0.0 sec, 27760 bytes code, 1268 bytes data
    测试数据 #0: Accepted, time = 0 ms, mem = 920 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 920 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 920 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 928 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 920 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 924 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 920 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 920 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 920 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 920 KiB, score = 10
    Accepted, time = 45 ms, mem = 928 KiB, score = 100
    pascal
    //
    var
    a:array[1..30000] of longint;
    w, n, i, j, s:longint;
    procedure qsort(l, r:longint);
    var
    i, j, p, t:longint;
    begin
    i:=l;
    j:=r;
    p:=a[(l+r) div 2];
    repeat
    while a[i]<p do inc(i);
    while a[j]>p do dec(j);
    if i<=j then begin
    t:=a[i];
    a[i]:=a[j];
    a[j]:=t;
    inc(i);
    dec(j)
    end;
    until i>j;
    if i<r then qsort(i, r);
    if l<j then qsort(l, j)
    end;
    begin
    readln(w);
    readln(n);
    for i:=1 to n do readln(a[i]);
    qsort(1, n);
    i:=1;
    j:=n;
    s:=0;
    while i<=j do begin
    if i<j then if a[i]+a[j]<=w then begin
    inc(i);
    dec(j);
    inc(s)
    end
    else begin
    dec(j);
    inc(s)
    end;
    if i=j then begin
    inc(i);
    inc(s)
    end;
    end;
    write(s)
    end.

  • 1

信息

ID
1409
难度
4
分类
贪心 点击显示
标签
递交数
8103
已通过
3192
通过率
39%
被复制
27
上传者