题解

229 条题解

  • 0
    @ 2009-10-25 11:41:54

    55555.........用桶排超时四个......

  • 0
    @ 2009-10-25 00:01:58

    我的经验是,这道题目不能用快排

    反正我是超时了

  • 0
    @ 2009-10-17 21:05:59

    这是动归?贪心秒杀

    var w,n,s,t,i,j:integer;

    y:boolean;

    a,b:array[0..30000] of integer;

    begin

    readln(w);

    readln(n);

    for i:=1 to n do

    begin

    readln(a[i]);

    inc(b[a[i]]);

    end;

    for i:=1 to n do

    if b[a[i]]>0 then

    begin

    dec(b[a[i]]);

    t:=w-a[i];

    y:=false;

    for j:=t downto 1 do

    if b[j]>0 then begin s:=s+1; y:=true; b[j]:=b[j]-1; break; end;

    if not(y) then s:=s+1;

    end;

    writeln(s);

    end.

  • 0
    @ 2009-10-17 13:03:57

    var

    h,i,j,n,w,s,left,right,x : longint ;

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

    procedure kuai(l,r:longint);

    var

    i,j,m,t:longint;

    begin

    i:=l;

    j:=r;

    m:=a[l];

    repeat

      while a[i]>m do inc(i);

      while a[j]

  • 0
    @ 2009-10-15 21:15:22

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    快排然后取两头。。。。终于没超时!!!!!

  • 0
    @ 2009-10-23 19:14:46

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案错误...

     ├ Hint: 我们也可以不写 ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 06:答案错误...

     ├ Hint: 可以留空 ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 07:答案错误...

     ├ Hint: 也就像下面这样 ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 08:答案错误... ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 09:答案错误... ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 10:答案错误... ├ 标准行输出

     ├ 错误行输出

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:40 有效耗时:0ms

    var

    h,i,j,n,w,s,left,right,x : longint ;

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

    procedure kuai(l,r:longint);

    var

    i,j,m,t:longint;

    begin

    i:=l;

    j:=r;

    m:=a[l];

    repeat

    while a[i]>m do inc(i);

    while a[j]

  • 0
    @ 2009-10-10 21:27:41

    狂掉RP!!!

    当年这题秒掉了现在卡了n次!!!

    明明是正确的程序!

  • 0
    @ 2009-09-22 00:21:45

    快排一次再双指针扫描

    排序O(nlogn)

    扫描O(n)

    时间复杂度O(nlogn)

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-09-20 10:01:08

    program p1409;

    var

    w:array[0..300] of longint;

    n,max,i,j,p:integer; m:longint;

    function xiao(x,y:integer):integer;

    begin

    if x>y then x:=y;

    xiao:=x;

    end;

    begin

    read(max,n);

    fillchar(w,sizeof(w),0);

    m:=0; i:=1000; j:=0;

    for i:=1 to n do

    begin

    read(p);

    inc(w[p]);

    if j0 do

    begin

    if (w[j]>=2) and (2*j0) and ((w[i]=0) or (j+i>max)) do dec(i);

    if i=0 then begin inc(m,w[j]); w[j]:=0; end

    else begin p:=xiao(w[j],w[i]); inc(m,p); w[j]:=w[j]-p; w[i]:=w[i]-p; end;

    end;

    while (w[j]=0) and (j>0) do dec(j)

    end;

    write(m);

    end.

    经典桶排序+贪心

    贪心原则:尽量用两个重量大的搭配成一组。也有一种做法是将大的与小的搭配,可以证明这两种贪心的效果是一样的。。。。。。。

    (注意处理当前最大重量的包自成组的情况;

    ---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|-

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-09-18 19:56:26

    quicksort+贪心=AC

    = =、

  • 0
    @ 2009-09-18 19:50:17

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-09-11 23:47:08

    求dp方程

  • 0
    @ 2009-09-14 18:48:01

    这题需要DP吗?

    纯粹的数学分析题。。

  • 0
    @ 2009-08-31 11:41:51

    第一次

    if a[k]+a[t]

  • 0
    @ 2009-08-28 16:16:53

    堆排还是快排啊

  • 0
    @ 2009-08-28 09:26:25

    贪心+快排=AC!

  • 0
    @ 2009-08-19 21:11:36

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    还是堆排写起来舒服

  • 0
    @ 2009-08-18 17:05:17

    看看咱的明明排序(受启发于“明明的随机数”一题,因而得名)

    program NOIP_2007_2;

    var a:array[0..30000]of integer;

    js:array[1..200]of integer;

    i,j,k,n,m,l,w,ans:longint;

    changed:boolean;

    procedure init;

    begin

    readln(w,n);

    fillchar(js,sizeof(js),0);

    for i:=1 to n do

    begin

    readln(l);

    inc(js[l]);

    end;

    for i:=1 to 200 do

    for j:=1 to js[i] do

    begin

    inc(m);

    a[m]:=i;

    end;

    end;

    begin

    init;

    k:=n;

    l:=0;

    while k>l do

    begin

    inc(l);

    if a[k]+a[l]

  • 0
    @ 2009-08-18 12:28:37

    注意边界!!!

  • 0
    @ 2009-08-13 18:36:10

    类型(?)   动态规划

    LZ会遭雷劈的。

信息

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