题解

229 条题解

  • 0
    @ 2012-11-08 22:01:13

    标准水题。。。

    不刷水题,天理难容!

    点这里查看程序源码+详细题解

  • 0
    @ 2012-10-30 17:10:11

    开始没看到上限二字 少了个=,没过……

    快排 用队列指针做 完美AC!!

    var

    n,w,i,s,head,tail:integer;

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

    procedure 快排:不赘述

    begin

    readln(w); readln(n); s:=0; head:=1; tail:=n;

    for i:=1 to n do readln(a[i]);

    qsort(1,n);

    while head

  • 0
    @ 2012-08-05 10:52:18

    点击查看代码

    数据比较水,开始没看到一组最多两个,都得90分,无语

  • 0
    @ 2010-04-15 17:43:27

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    没看题解,又做对一道了 -。-

  • 0
    @ 2010-04-15 17:02:19

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

    type

    arr=array[1..30000] of integer;

    var

    w,n,num,zh,i,j,k,temp:integer;

    p:arr;

    procedure pai(l,r:integer);

    var

    x,y,zhong:integer;

    begin

    zhong:=p[(l+r)div 2];

    x:=l; y:=r;

    repeat

    while (xzhong) do x:=x+1;

    while (x

  • 0
    @ 2010-04-13 17:28:06

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    var

    lzj,n,s:longint;

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

    procedure swap(var a,b:longint);

    begin

    if ab then

    begin

    a:=a xor b;

    b:=a xor b;

    a:=a xor b;

    end;

    end;

    procedure qsort(l,r:longint);

    var

    i,m,j:longint;

    begin

    i:=l;j:=r;

    m:=a[random(j-i)+i];

    repeat

    while a[i]m do dec(j);

    if ij;

    if l=j then

    begin

    if i=j then inc(l);

    over:=true;

    end;

    end;

    writeln(l);

    end;

    begin

    init;

    qsort(1,n);

    find;

    end.var

    j,n,s:longint;

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

    procedure swap(var a,b:longint);

    begin

    if ab then

    begin

    a:=a xor b;

    b:=a xor b;

    a:=a xor b;

    end;

    end;

    procedure qsort(l,r:longint);

    var

    i,m,j:longint;

    begin

    i:=l;j:=r;

    m:=a[random(j-i)+i];

    repeat

    while a[i]m do dec(j);

    if ij;

    if l=j then

    begin

    if i=j then inc(l);

    over:=true;

    end;

    end;

    writeln(l);

    end;

    begin

    init;

    qsort(1,n);

    find;

    end.

  • 0
    @ 2010-04-13 17:18:26

    program p1409;

    type arr=array[0..30000] of integer;

    var i,j,x,k,w,s,n:integer;

    p:arr;

    procedure qs(var b:arr; s,t:integer);

    begin

    i:=s;j:=t;x:=b[i];

    repeat

    while (b[j]>=x) and (j>i) do j:=j-1;

    if j>i then

    begin

    k:=b[i]; b[i]:=b[j]; b[j]:=k;

    end;

    while (b[i]

  • 0
    @ 2009-11-10 16:22:01

    这被分到DP里面?

    贪心嘛……

  • 0
    @ 2009-11-10 13:18:46

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    type

    tlist=array[0..40000]of longint;

    var

    a1,x1,y1:tlist;

    i,j,k,l,m,n,max,c,q:longint;

    procedure qsort(var a:tlist);

    procedure sort(l,r:longint);

    var

    i,j,x,y: longint;

    begin

    i:=l;

    j:=r;

    x:=a[(l+r) div 2];

    repeat

    while a[i]j;

    if l

  • 0
    @ 2009-11-09 21:19:20

    动态规划真的不知道怎么办,贪心是如此的自然

    第一次以为较大的要找一个较小中的可以和他组合的最大一个,后来发现,不必这样

    因为这样比较大的再小的较大的可以和更小的组合

    因此最终用了双指针扫描,比for 好用也更直观,for的话每次还得优化

    program p1409;

    var w,n,total,i:longint;

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

    procedure init;

    var i:longint;

    begin

    total:=0;

    readln(w);

    readln(n);

    for i:=1 to n do readln(a[i]);

    end;

    procedure qsort(l,r:longint);

    var i,j,t,tmp:longint;

    begin

    i:=l; j:=r; t:=a[i];

    repeat

    while (a[j]>=t) and (j>i) do dec(j);

    if j>i then begin tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp end;

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

    if j>i then begin tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp; end;

    until i=j;

    a[i]:=t;

    dec(i); inc(j);

    if l

  • 0
    @ 2009-11-08 08:57:21

    如此动归!!!

  • 0
    @ 2009-11-07 17:14:24

    为什么这道题被放在DP的分类里面?

  • 0
    @ 2009-11-07 10:33:42

    Flag    Accepted

    题号    P1409

    类型(?)   贪心

    通过    2392人

    提交    5888次

    通过率    41%

    难度    1

    贪心,一次A。。。

  • 0
    @ 2009-11-04 14:30:14

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

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

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

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

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

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

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

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

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

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

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

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

    #include

    #include

    int sortquick(int sortArray[], int left, int right)

    {

    int l = left;

    int r = right;

    int indexData = sortArray[l];

    int index = l;

    while (l < r)

    {

    if (index == l)

    {

    while (r > l)

    {

    if (sortArray[r] >= indexData)

    {

    r--;

    }

    else

    {

    sortArray[l] = sortArray[r];

    sortArray[r] = indexData;

    index = r;

    break;

    }

    if (sortArray[r] == indexData)

    {

    index = r;

    if (r > l)

    {

    r--;

    }

    }

    }

    }

    else if (index == r)

    {

    while (l < r)

    {

    if (sortArray[l] left)

    {

    sortquick(sortArray, left, index - 1);

    }

    if(right>index)

    {

    sortquick(sortArray, index + 1, right);

    }

    }

    main()

    {int max,n,m=0,k=0,l;

    int num=0;

    scanf("%d/n",&max);

    scanf("%d/n",&n);

    int f[30000];

    for(l=0;l=0;l--)

    {if(mmax&&f[l]

  • 0
    @ 2009-11-02 16:40:47

    从题目中叙述“但每组最多只能包括两件纪念品”的那一刻开始,便注定了这题难逃水题的命运!

    处理结尾时注意,以免比答案少一!

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

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    var

    n,s:longint;

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

    procedure swap(var a,b:longint);

    begin

    if ab then

    begin

    a:=a xor b;

    b:=a xor b;

    a:=a xor b;

    end;

    end;

    procedure qsort(l,r:longint);

    var

    i,m,j:longint;

    begin

    i:=l;j:=r;

    m:=a[random(j-i)+i];

    repeat

    while a[i]m do dec(j);

    if ij;

    if l=j then

    begin

    if i=j then inc(l);

    over:=true;

    end;

    end;

    writeln(l);

    end;

    begin

    init;

    qsort(1,n);

    find;

    end.

  • 0
    @ 2009-10-31 10:44:16

    #include

    using namespace std;

    int n,w,a[201],res;

    int main()

    {

    cin>>w>>n;

    int i,t,l=1,r=w;

    for(i=1;i>t;

    a[t]++;

    }

    while(l

  • 0
    @ 2009-10-30 19:22:40

    贪心都能过

    水题!!!!!!!!!!!!!!!!!!!!!!

    !!!!!!!!!!!!!!!!!!!!!!!!

    !!!!!!!!!!!!!!!!!!!!!!!!

    !!!!!!!!!!!!!!!!!!!!!!!!

    !!!!!!!!!!!!!!!!!!!!!!!!

  • 0
    @ 2009-10-29 19:27:45

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    怨念啊,当年没用快排,冒跑才20分......

  • 0
    @ 2009-10-28 17:49:39

    program luffy;

    var

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

    i,j,k,m,n:longint;

    procedure s(l,r:longint);

    var

    i,j,x,temp:longint;

    begin

    i:=l;

    j:=r;

    x:=a[(l+r) div 2];

    repeat

    while a[i]x do dec(j);

    if ij;

    if l

  • 0
    @ 2009-10-27 19:36:38

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    快排+贪心=秒杀

信息

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