题解

249 条题解

  • 0
    @ 2006-11-06 10:11:46

    AC。

    但是不明白,为虾米TT高度=0不可以摘?题目理解真的很难啊。

  • 0
    @ 2006-11-06 09:43:37

    为什么编题的人要这么狠,题目中根本就没有说如果是0的情况,按照常理,如果陶陶的高度是0的话不也可以捡起来的吗?

  • 0
    @ 2006-11-06 09:40:37

    测试数据中当陶陶高度为0时全不摘才能AC

  • 0
    @ 2006-11-06 09:41:00

    TMD 告诉大家过不了的原因

    是因为当陶陶的高度为0时,它不存在,你无法摘到他!!!!

    所以一般人在扫描时都会将max赋成负数,所以一定过不了,让max=0

    出题人太猥琐了。。。

  • 0
    @ 2006-11-06 09:11:34

    毫无意义的方法……

    只要枚举每个苹果然后枚举每个陶陶,取一个最大的而且高度小于苹果的陶陶,然后去掉。再枚举剩下的苹果和剩下的陶陶,最终苹果被枚举完了,但是陶陶可能剩下很多……

    把剩下的陶陶的个数输出就行了……

  • 0
    @ 2006-11-10 00:19:19

    这题我彻底fente了

    莫非咱们和Dai牛的理解方式不一样……?

    终于AC……0啊0啊0……

    做法和我崇拜的lolanv一样

    两个qsort+线性扫描

    Complexity:O(2*nlogn+n)=O(nlogn)

  • 0
    @ 2006-11-06 08:40:50

    陷阱在哪???我觉不用排序呀~~ 硬搜也能过吧~~我也只过最后一个点

  • 0
    @ 2006-11-06 08:31:45

    为什么只过最后一个点阿?研究了半天……

  • 0
    @ 2006-11-06 09:56:07

    昏,这种题目真的没有水平,0高度的陶陶,不用排序,直接线性扫描就OK

  • 0
    @ 2006-11-06 08:19:25

    两个qs+线性扫描 nlogn

  • 0
    @ 2006-11-06 06:47:32

    这道题目我是第一个ac的???

  • -1
    @ 2019-06-25 19:38:38
    #include <iostream>
    #include <algorithm>
    #define maxn 2016
    using namespace std;
    
    int main()
    {
        int a[maxn],b[maxn],n,m;
        while(cin>>n>>m){
            int sum=m;
            for(int i=0;i<n;i++){
                cin>>a[i];
            }
            for(int i=0;i<m;i++){
                cin>>b[i];
            }
            sort(a,a+n);
            sort(b,b+m);
    
            for(int i=n-1;i>=0;i--){
                for(int j=m-1;j>=0;j--){
                    if(a[i]>b[j]&&b[j]!=0){
                        b[j]=0;
                        sum--;
                        j=0;
                    }
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }
    
    
  • -1
    @ 2018-11-30 19:30:27

    #include<stdio.h>
    int main(void)
    {
    int i,j,temp,a,t,apple[2000],tao[2000],count=0;
    scanf("%d%d",&a,&t);
    for(i=0;i<a;i++) scanf("%d",&apple[i]);
    for(i=0;i<t;i++) scanf("%d",&tao[i]);
    for(i=0;i<t-1;i++)
    for(j=i+1;j<t;j++) if(tao[i]<tao[j]) {
    temp=tao[i];
    tao[i]=tao[j];
    tao[j]=temp;
    }
    for(i=0;i<a;i++)
    for(j=0;j<t;j++){
    if(tao[j]>0) if(apple[i]>tao[j]) {tao[j]=-1;break;}
    }
    for(i=0;i<t;i++) if(tao[i]>=0) count++;
    printf("%d\n",count);
    return 0;
    }
    要注意三点:
    1、要先对陶陶从高到矮排序。
    2、苹果只能摘比自己矮的陶陶,和自己一样高的不能摘。
    3、身高为0的陶陶不能摘。

  • -1
    @ 2018-10-15 16:49:48

    #include<iostream>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    int apple[2001] = { 0 };
    int taotao[2001] = { 0 };
    int book[1001] = { 0 };
    int main()
    {
    int n, m,i,j,account=0;
    cin >> n >> m;
    for (i = 0; i < n; i++)
    cin >> apple[i];
    for (j = 0; j < m; j++)
    cin >> taotao[j];
    //这个时候i=n-1 j=m-1
    sort(apple, apple + n);
    sort(taotao, taotao + m);
    for (i=n-1; i >= 0; i--)
    {
    for (; j >= 0; j--)
    {
    if (apple[i] > taotao[j] && taotao[j] != 0)
    {
    j=j-1;
    account++;
    break;
    }
    }
    }
    cout << m - account;
    return 0;
    }

  • -1
    @ 2018-09-14 12:17:55

    //
    // main.cpp
    // algorithm
    //
    // Created by apple on 2018/9/7.
    // Copyright © 2018 apple. All rights reserved.
    //

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <map>
    #include <vector>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <iomanip>
    #include <set>
    #include <cstring>

    using namespace std;

    int n, m;
    vector<int> ha, ht;

    int main(){
    cin.sync_with_stdio(false);
    cin >> n >> m;
    int iv;
    for(int i = 0; i < n; i++){cin >> iv; ha.push_back(iv);}
    for(int i = 0; i < m; i++){cin >> iv; if(iv != 0) ht.push_back(iv);}
    if(ht.size() == 0) {
    cout << m << endl;
    return 0;
    }
    sort(ht.begin(), ht.end());
    int ans = m;
    for(int i = 0; i < n; i++){
    int pos = lower_bound(ht.begin(), ht.end(), ha[i]) - ht.begin();
    if(pos > 0){
    ans--;
    ht.erase(ht.begin() + pos - 1);
    }
    }
    cout << ans << endl;
    return 0;
    }

    //之前几次lower_bound都用错了, WA了好几次, 返回的是大于等于要找值的第一个数.

  • -1
    @ 2018-09-14 12:17:54

    //
    // main.cpp
    // algorithm
    //
    // Created by apple on 2018/9/7.
    // Copyright © 2018 apple. All rights reserved.
    //

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <map>
    #include <vector>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <iomanip>
    #include <set>
    #include <cstring>

    using namespace std;

    int n, m;
    vector<int> ha, ht;

    int main(){
    cin.sync_with_stdio(false);
    cin >> n >> m;
    int iv;
    for(int i = 0; i < n; i++){cin >> iv; ha.push_back(iv);}
    for(int i = 0; i < m; i++){cin >> iv; if(iv != 0) ht.push_back(iv);}
    if(ht.size() == 0) {
    cout << m << endl;
    return 0;
    }
    sort(ht.begin(), ht.end());
    int ans = m;
    for(int i = 0; i < n; i++){
    int pos = lower_bound(ht.begin(), ht.end(), ha[i]) - ht.begin();
    if(pos > 0){
    ans--;
    ht.erase(ht.begin() + pos - 1);
    }
    }
    cout << ans << endl;
    return 0;
    }

    //之前几次lower_bound都用错了, WA了好几次, 返回的是大于等于要找值的第一个数.

  • -1
    @ 2018-09-08 23:51:28

    #include<iostream>
    #include<algorithm>
    using namespace std;
    bool compare(int a, int b) {
    return a > b;
    }
    int main() {
    int a[2000];
    int b[2000];
    int n, m;
    int sum = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    }
    for (int i = 0; i < m; i++)
    scanf("%d", &b[i]);
    sort(b, b + m, compare);
    sort(a, a + n, compare);
    for (int i = 0; i < n; i++) {
    for(int j=0;j<m;j++)
    if (a[i] > b[j] && b[j] > 0) {
    sum++;
    b[j] = 0;
    break;
    }
    }
    cout << m - sum << endl;
    return 0;
    }

  • -1
    @ 2018-08-06 17:59:34
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        int apple[2000]={0},tao[2000]={0};
        int anum,tnum,i,j,temp,sum = 0;
        scanf("%d%d",&anum,&tnum);
        for(i = 0; i < anum; i++)
            scanf("%d",apple+i);
        for(i = 0; i < tnum; i++)
            scanf("%d",tao+i);
        for(i = 0; i < anum; i++)
        {
            temp = 0;
            while((tao[temp] >= apple[i] || tao[temp] == 0) && temp != tnum)
                temp++;
            if(temp == tnum)
                continue;
            for(j = temp + 1; j < tnum; j++)
            {
                if(tao[j] < apple[i] && tao[j] != 0 && tao[temp] < tao[j])
                    temp = j;
            }
            sum++;
            tao[temp] = 0;
        }
        printf("%d\n",tnum - sum);
        return 0;
    }
    
    
  • -1
    @ 2018-07-30 15:54:52

    太A

  • -1
    @ 2017-12-03 14:14:53

    数组容量一百0分,一千10分,一万100分,呃呃呃
    #include<stdio.h>
    int main()
    {
    int m,n,c,d=0,a[10000]={0},b[10000]={0};
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
    scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++)
    {
    scanf("%d",&b[i]);
    }
    for(int i=1;i<=n;i++)
    {
    c=0;
    for(int j=1;j<=m;j++)
    {
    if(b[j]==0)continue;
    if(a[i]>b[j]&&b[c]<b[j])c=j;
    }
    if(c!=0){b[c]=0;d++;}
    }
    printf("%d\n",m-d);
    return 0;
    }

信息

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