题解

249 条题解

  • 0
    @ 2015-04-16 21:21:08

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 556 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 556 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 556 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 560 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 556 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    Accepted, time = 90 ms, mem = 560 KiB, score = 100
    代码
    #include<iostream>
    using namespace std;
    int a[5000],b[5000];
    void qsorta(int l,int r)
    {
    int i,j,mid,p;
    i=l;
    j=r;
    mid=a[(l+r) / 2]; //将当前序列在中间位置的数定义为分隔数
    do
    {
    while (a[i]<mid) i++; //在左半部分寻找比中间数大的数
    while (a[j]>mid) j--; //在右半部分寻找比中间数小的数
    if (i<=j)
    { //若找到一组与排序目标不一致的数对则交换它们
    p=a[i];
    a[i]=a[j];
    a[j]=p;
    i++;
    j--; //继续找
    }
    }
    while (i<=j); //注意这里不能有等号
    if (l<j) qsorta(l,j); //若未到两个数的边界,则递归搜索左右区间
    if (i<r) qsorta(i,r);
    }
    void qsortb(int l,int r)
    {
    int i,j,mid,p;
    i=l;
    j=r;
    mid=b[(l+r) / 2];
    do
    {
    while (b[i]<mid) i++;
    while (b[j]>mid) j--;

    if (i<=j)
    {

    p=b[i];
    b[i]=b[j];
    b[j]=p;
    i++;
    j--;

    }
    }
    while (i<=j);

    if (l<j) qsortb(l,j);

    if (i<r) qsortb(i,r);
    }

    int main()
    {
    int m,n,i,j,s=0;
    cin >> n >> m;
    for (i=1; i <= n; i++)
    cin >> a[i];
    for (i=1; i <= m; i++)
    cin >> b[i];
    qsorta(1,n);
    qsortb(1,m);
    for (i=1; i <= m; i++)
    if (b[i]==0)
    {
    s++;
    b[i]=-1;
    }
    for (i=1; i <= n; i++)
    for (j=1; j <= m; j++)
    if ((a[i]>b[j])&&(b[j]>0))
    {
    b[j]=0;
    break;
    }
    for (j=1; j <= m; j++)
    if (b[j]>0)
    s++;
    cout << s;
    return 0;
    }

  • 0
    @ 2015-03-04 21:49:29

    求各位大神帮忙看一下为什么错了C++
    #include<iostream>
    using namespace std;
    int main()
    {
    int n,m,i,j,k,l,o,p,q,c,e=0,d=0,a[2000],b[2000];
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
    cin>>a[i];
    }
    for(j=0;j<m;j++)
    {
    cin>>b[j];
    }
    for(k=0;k<m-1;k++)
    {
    for(l=0;l<m-1;l++)
    {
    if(b[l]<b[l+1])
    {
    c=b[l];
    b[l]=b[l+1];
    b[l+1]=c;
    }
    }
    }
    for(q=0;q<n;q++)
    {
    if(e<a[q])
    {
    e=a[q];
    }
    }
    for(o=0;o<n;o++)
    {
    for(p=0;p<m;p++)
    {
    if(a[o]>b[p])
    {
    d++;
    b[p]=e+1;
    break;
    }
    }
    }
    d=m-d;
    cout<<d;
    return 0;
    }

  • 0
    @ 2015-03-01 09:48:57

    program x1291;
    var
    a,b:array[1..2000]of longint;
    n,m,i,j,k,l,x,y:longint;
    begin
    assign(input,'1.txt');
    reset(input);
    readln(n,m);
    for i:=1 to n do readln(a[i]);
    for i:=1 to m do readln(b[i]);
    for i:=1 to m-1 do
    for j:=i+1 to m do
    if b[i]<b[j] then
    begin
    k:=b[i];b[i]:=b[j];b[j]:=k;
    end;
    for i:=1 to m do
    for j:=1 to n do
    begin
    if (a[j]>b[i])and(b[i]<>0) then begin inc(x); a[j]:=0;break;
    end;end;
    l:=m-x;
    writeln(l);
    end.

  • 0
    @ 2015-02-05 17:30:43

    program haer;
    var
    tt,app:array[1..2000] of integer;
    i,j,ls:integer;
    nt,na:integer;
    num:integer;
    begin
    readln(na,nt);
    num:=nt;

    for i:=1 to na do
    read(app[i]);

    for i:=1 to nt do
    begin
    read(tt[i]);
    end;

    for i:=1 to nt-1 do
    for j:=i+1 to nt do
    if tt[i]<tt[j] then
    begin
    ls:=tt[i];
    tt[i]:=tt[j];
    tt[j]:=ls;
    end;

    for i:=1 to na-1 do
    for j:=1 to na do
    if app[i]<app[j] then
    begin
    ls:=app[i];
    app[i]:=app[j];
    app[j]:=ls;
    end;

    for i:=1 to na do
    begin
    for j:=1 to nt do
    if (tt[j]<app[i])and(tt[j]>0) then
    begin
    tt[j]:=0;
    dec(num);
    break;
    end;
    end;

    write(num);
    end.

    我去真的要把苹果也排个序……
    话说这个程序拷到隔壁tyvj就WA【跪着】求解求科普……
    还有隔壁那个题目有“快排”……确实没给数据范围来着……

  • 0
    @ 2014-12-29 19:03:25

    还研究啥呀,人家题目不是说了摘取的顺序按照输入的“苹果够到的最大高度”的顺序来摘。
    审题呀!
    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int apple2[10000],tt2[10000];
    int apple,tt,tt3=0;
    int ser(int n)
    {
    for(int i=1;i<=tt;i++)
    {
    if(n>tt2[i]&&tt2[i]!=0)
    {
    tt2[i]=10000;
    return tt3++;
    }
    }
    }
    int compare(const int&a,const int&b)
    {
    if(a>b)return 1;
    else return 0;
    }
    int main()
    {
    cin>>apple>>tt;
    for(int i=1;i<=apple;i++)
    cin>>apple2[i];
    for(int i=1;i<=tt;i++)
    cin>>tt2[i];
    sort(tt2+1,tt2+tt+1,compare);

    for(int i=1;i<=apple;i++)
    {ser(apple2[i]);
    }
    cout<<tt-tt3<<endl;
    system("pause");
    return 0;
    }

  • 0
    @ 2014-12-25 17:40:46

    话说这题为各位的题解都把2个数组都排序了??不是排陶陶就能AC了么?

    好吧,研究了一下,能给出为什么不用排苹果了。
    因为贪心思路,每个苹果都会摘取自己力所能及的陶陶,不必要每个苹果都去摘自己最大能力下的陶陶
    比如陶陶是10 6 7,苹果是8 10,让10摘6,8摘7或者10摘7,8摘6都是一样的。

    怎么说呢,反正那些一般苹果摘不到的陶陶,总归是有个苹果能去把他摘下来的。而那些小苹果随便怎么摘,顺序都没事。
    因此只要把陶陶从大到小摘下来即可。

  • 0
    @ 2014-12-25 17:38:20

    我擦真水,不小心没取消冒泡排序的注释,还能拿50分,笑。

    AC还是不难的。

    block code

    program ex;
    var n,m,i,k,a,ans:longint;
    apple,data:array[1..2000] of longint;
    bo:boolean;
    begin
    read(n,m);
    ans:=m;
    bo:=true;
    for i:=1 to n do
    read(apple[i]);

    for i:=1 to m do
    read(data[i]);

    for i:=1 to m do
    begin
    if bo=false then
    break;
    bo:=false;
    for k:=1 to m-1 do
    if data[k]<data[k+1] then
    begin
    a:=data[k]; data[k]:=data[k+1]; data[k+1]:=a; bo:=true;
    end;
    end;

    for i:=1 to n do
    for k:=1 to m do
    if (apple[i]>data[k]) and (data[k]<>0) then
    begin
    data[k]:=99999; dec(ans); break;
    end;

    write(ans);

    end.

    • @ 2014-12-25 17:39:19

      为什么2个数组都要排序???只要排陶陶不就结了么?

  • 0
    @ 2014-12-09 19:18:09

    评测结果
    编译成功

    Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
    Copyright (c) 1993-2014 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(19,20) Warning: Variable "sum" does not seem to be initialized
    Linking foo.exe
    20 lines compiled, 0.1 sec , 28416 bytes code, 1628 bytes data
    1 warning(s) issued

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

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

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

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

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

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

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

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

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

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

    Accepted, time = 183 ms, mem = 748 KiB, score = 100

    代码
    var
    a,b:array[0..2001] of longint;
    t,n,m,i,j,sum:longint;
    begin
    readln(n,m);
    for i:=1 to n do read(a[i]);
    for i:=1 to m do read(b[i]);
    for i:=1 to n-1 do
    for j:=i+1 to n do
    if a[i]<a[j] then
    begin t:=a[i];a[i]:=a[j];a[j]:=t;end;
    for i:=1 to m-1 do
    for j:=i+1 to m do
    if b[i]<b[j] then
    begin t:=b[i];b[i]:=b[j];b[j]:=t;end;
    for i:=1 to n do
    for j:=1 to m do
    if (a[i]>b[j]) and (b[j]<>0) then
    begin inc(sum);b[j]:=0;break;end;
    writeln(m-sum);
    end.

  • 0
    @ 2014-11-06 19:32:38

    水题但深坑!!!!!Orz Orz 花了一个多小时。。。。。。

  • 0
    @ 2014-10-31 17:11:35

    var a,b:array[1..10000]of integer;
    i,j,m,t,n,sum:integer;
    begin
    read(n,m);
    for i:=1 to n do read(a[i]); //读入两个数组

    for i:=1 to m do read(b[i]);
    for i:=1 to n-1 do //冒泡排序a数组
    for j:=1 to n-i do
    if a[j]<a[j+1] then
    begin
    t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t;
    end;
    for i:=1 to n-1 do //冒泡排序b数组
    for j:=1 to n-i do
    if b[j]<b[j+1] then
    begin
    t:=b[j]; b[j]:=b[j+1]; b[j+1]:=t;
    end;
    sum:=0; //计数器清零
    for i:=1 to n do
    for j:=1 to m do
    if (a[i]>b[j]) and (b[j]<>0) then //如果陶陶的高度小于不等于零苹果的高度则
    begin
    b[j]:=0; //清零
    inc(sum);
    break; //退出循环
    end;
    write(sum);
    end.

  • 0
    @ 2014-10-31 17:10:37

    var a,b:array[1..10000]of integer;
    i,j,m,t,n,sum:integer;
    begin
    read(n,m);
    for i:=1 to n do read(a[i]); //读入两个数组

    for i:=1 to m do read(b[i]);
    for i:=1 to n-1 do //冒泡排序a数组
    for j:=1 to n-i do
    if a[j]<a[j+1] then
    begin
    t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t;
    end;
    for i:=1 to n-1 do 冒泡排序b数组
    for j:=1 to n-i do
    if b[j]<b[j+1] then
    begin
    t:=b[j]; b[j]:=b[j+1]; b[j+1]:=t;
    end;
    sum:=0; //计数器清零
    for i:=1 to n do
    for j:=1 to m do
    if (a[i]>b[j]) and (b[j]<>0) then //如果陶陶的高度小于不等于零苹果的高度则
    begin
    b[j]:=0; //清零
    inc(sum);
    break; //退出循环
    end;
    write(m-sum);
    end.

  • 0
    @ 2014-08-04 16:37:51

    40题!

    记录信息
    评测状态 Accepted
    题目 P1291 苹果摘陶陶
    递交时间 2014-08-04 16:36:32
    代码语言 C++
    评测机 VijosEx
    消耗时间 106 ms
    消耗内存 272 KiB
    评测时间 2014-08-04 16:36:38
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 31 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 106 ms, mem = 272 KiB, score = 100

    注:高度为0的也算涛涛……

  • 0
    @ 2014-06-10 14:17:37

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    int n,m,h1[2001],h2[2001],i,sum,j;
    bool v[2001];
    int main()
    {
    cin>>n>>m;
    memset(v,true,sizeof(v));
    for(i=1;i<=n;i++) cin>>h1[i];
    for(i=1;i<=m;i++) cin>>h2[i];
    sort(h2+1,h2+m+1);
    cout<<endl;
    sum=0;
    for(i=1;i<=n;i++){
    for(j=m;j>=1;j--){
    if((h1[i]>h2[j]) && (v[j]) && (h2[j]>0)){
    v[j]=false;
    sum++;
    break;
    }
    }
    }
    cout<<m-sum<<endl;
    return 0;
    }

  • 0
    @ 2014-04-28 20:06:18

    为啥要sort ?
    不sort一样15ms啊

  • 0
    @ 2014-03-24 20:02:56

    水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 816 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 816 KiB, score = 10
    Accepted, time = 15 ms, mem = 816 KiB, score = 100

    type arr1=array[0..10001] of longint;

    var a,b:arr1;i,k,h1,n,h2,m:longint;

    procedure px(l,r:longint; var y:arr1);

    var i,j,m,t:longint;

    begin

    i:=l; j:=r; m:=y[(l+r )div 2];

    repeat

    while y[i]<m do inc(i);

    while y[j]>m do dec(j);

    if i<=j then

    begin

    t:=y[i]; y[i]:=y[j]; y[j]:=t;

    inc(i); dec(j);

    end;

    until i>j ;

    if l<j then px(l,j,y);

    if r>i then px(i,r,y);

    end;

    begin

    readln(n,m);

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

    for i:=1 to m do readln(b[i]);

    px(1,n,a);px(1,m,b);h1:=1;h2:=1;k:=m;

    while (h1<=n)and(h2<=m) do

    begin

    if b[h2]=0 then begin inc(h2);continue;end;

    if a[h1]>b[h2] then begin dec(k);inc(h1);inc(h2);end

    else inc(h1);

    end;

    writeln(k);

    end.

  • 0
    @ 2014-03-23 20:21:41

    坑啊= =读题要仔细,阅读理解要好:
    1. 苹果们上场的顺序不是输入顺序,是__跳跃高度从大到小排序!__(有歧义)
    2. 苹果们只能摘到小于他们的跳跃高度的陶陶,__不能等于!__(题目没读仔细)
    3. 高度0的陶陶不能摘!(这个倒是题目里就有- -)

    #include <cstdio>
    #include <algorithm>

    using namespace std;

    bool com(int a,int b){
    return a>b;
    }

    int main(){
    int n,m;
    int ab[2000];
    int tree[301],temp;

    int i,j;//for loop

    while( ~scanf("%d%d",&n,&m) ){
    //init
    for(i=0;i<=300;i++)
    tree[i] = 0;
    //input
    for(i=0;i<n;i++)
    scanf("%d",ab+i);
    for(i=0;i<m;i++){
    scanf("%d",&temp);
    tree[temp]++;
    }

    //sort
    sort(ab,ab+n,com);

    //start
    for(i=0;i<n;i++){
    for(j=ab[i]-1;j>0;j--){
    if(tree[j]>0){
    tree[j]--;
    break;
    }
    }
    }

    //count Taotao on the tree
    temp = 0;
    for(i=0;i<=300;i++)
    temp += tree[i];
    printf("%d\n",temp);
    }
    return 0;
    }

    • @ 2014-03-24 20:03:46

      感谢你的提醒
      2. 苹果们只能摘到小于他们的跳跃高度的陶陶,不能等于!(题目没读仔细)

    • @ 2014-12-25 17:50:33

      1不影响结果,你别误导别人

  • 0
    @ 2013-12-01 21:20:11

    不要想复杂,大水题,也不要把m,n看反。。。

    Block code

    #include <cstdio>
    #include <algorithm>

    const int MAXN = 2012;
    int n,m,taotao,ans,apple[MAXN];

    bool com(int a,int b){
    return a<b;
    }

    void solve(){
    scanf("%d %d",&n,&m);
    ans=m;
    for (int i=0;i<n;i++)
    scanf("%d",&apple[i]);

    std::sort(apple,apple+n,com);

    for (int i=0;i<m;i++){
    scanf("%d",&taotao);
    if (taotao!=0){
    for (int j=0;j<n;j++){
    if (apple[j]>taotao){
    apple[j]=-1;ans--;
    break;
    }
    }

    }
    }
    printf("%d",ans);
    }

    int main(){
    solve();
    return 0;
    }

  • 0
    @ 2013-11-24 21:41:29

    大虾帮查
    program Project1;

    var
    a, b: array[1..20000] of longint;
    i, j, n, m: longint;

    procedure qsort(x, y: longint);
    var
    i, j, mid, p: longint;
    begin
    i := x;
    j := y;
    mid := a[(x + y) div 2];
    repeat
    while a[i] < mid do
    Inc(i);
    while a[j] > mid do
    j := j - 1;
    if i <= j then
    begin
    p := a[i];
    a[i] := a[j];
    a[j] := p;
    Inc(i);
    j := j - 1;
    end;
    until i > j;
    if x < j then
    qsort(x, j);
    if i < y then
    qsort(i, y);
    end;

    begin
    readln(n, m);
    for i := 1 to n do
    readln(a[i]);
    qsort(1, n);
    b := a;
    for i := 1 to n do
    if b[i] = 0 then
    Dec(n);
    for i := 1 to m do
    readln(a[i]);
    qsort(1, n);
    for i := n downto 1 do
    for j := m downto 1 do
    if (b[i] > a[j]) and (a[j] <> 0) then
    begin
    Dec(n);
    a[j] := 0;
    break;
    end;
    writeln(n);
    end.

  • 0
    @ 2013-09-07 10:20:15

    大坑
    原来以下是指>,不是>=
    #include <iostream>
    #include <algorithm>
    #include <memory.h>
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    using namespace std;
    int n,m,h1[2001],h2[2001],i,sum,j;
    bool v[2001];
    int main(int argc, char *argv[]) {
    cin>>n;
    cin>>m;
    memset(v,true,sizeof(v));
    for(i=1;i<=n;i++){
    cin>>h1[i];
    }
    for(i=1;i<=m;i++){
    cin>>h2[i];
    }
    sort(h2+1,h2+m+1);
    cout<<endl;
    sum=0;
    for(i=1;i<=n;i++){
    for(j=m;j>=1;j--){
    if((h1[i]>h2[j]) and (v[j]) and (h2[j]>0)){
    v[j]=false;
    sum++;
    break;
    }
    }
    }
    cout<<m-sum<<endl;
    }

  • 0
    @ 2013-07-23 12:57:16

    测试数据 #0: Accepted, time = 15 ms, mem = 576 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 572 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 572 KiB, score = 10
    测试数据 #3: Accepted, time = 3 ms, mem = 572 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 572 KiB, score = 10
    测试数据 #5: Accepted, time = 7 ms, mem = 576 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 576 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 568 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 576 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 572 KiB, score = 10
    Accepted, time = 115 ms, mem = 576 KiB, score = 100

信息

ID
1291
难度
6
分类
贪心 点击显示
标签
(无)
递交数
9765
已通过
2342
通过率
24%
被复制
17
上传者