80求解

P1478 陶陶摘苹果(升级版)

abc_s1 @ 2024-09-25 20:55:57

#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
struct pp{
    int x,y;
}apple[N];
bool cmp(pp x,pp y){
    return x.y<y.y;
}
int n,s,a,b,c,num=0;
int main(){
    cin>>n>>s;
    cin>>a>>b;
    c=a+b;
    for(int i=1;i<=n;i++){
        cin>>apple[i].x>>apple[i].y;
    }
    sort(apple+1,apple+1+n,cmp);
    for(int i=1;i<=n;i++){
        if(s<0){
            break;
        }
        if(c>=apple[i].x){
            num++;
            s-=apple[i].y;
        }

    }
    cout<<num-1;
    return 0;
}

by wjy314 @ 2024-09-25 21:08:56


#include <bits/stdc++.h>
using namespace std;
const int N=1e5;
struct pp{
    int x,y;
}apple[N];
bool cmp(pp x,pp y){
    return x.y<y.y;
}
int n,s,a,b,c,num=0;
int main(){
    cin>>n>>s;
    cin>>a>>b;
    c=a+b;
    for(int i=1;i<=n;i++){
        cin>>apple[i].x>>apple[i].y;
    }
    sort(apple+1,apple+1+n,cmp);
    for(int i=1;i<=n;i++){
        if(s<apple[i].y){
            break;
        }
        if(c>=apple[i].x){
            num++;
            s-=apple[i].y;
        }

    }
    cout<<num;
    return 0;
}

by YOU_QAQ @ 2024-09-25 21:11:43

#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, s, h, tao, cnt;
struct node{
    int x, y;
}c[5005];
bool cmp(node x,node y){
    return x.y < y.y;
}
int main(){

    cin >> n >> s >> h >> tao;
    tao += h;
    for(int i = 1;i <= n;i++){
        cin >> c[i].x >> c[i].y;
    }
    sort(c + 1,c + 1 + n,cmp);
    for(int i = 1;i <= n;i++){
        if(s < c[i].y){
            cout << cnt;
            return 0;
        }
        if(tao >= c[i].x){
            cnt++;
            s = s - c[i].y;
        }
    }
    cout << cnt; 

    return 0;
} 

@abc_s1 求关注


by ChenJove @ 2024-10-24 16:28:01

#include<bits/stdc++.h>
using namespace std;

struct apple{
    int h;
    int w;
}; 
apple a[5010];
bool cmp(apple a,apple b){
    if(a.w!=b.w){
        return a.w<b.w; 
    }
    else{
        return a.h<b.h;
    }
}
int main(){
    int n,s;
    cin>>n>>s;
    int chair,arm;
    cin>>chair>>arm;
    if(n==0){
        cout<<0;
        return 0;
    }
    for(int i=0;i<n;i++){
        cin>>a[i].h>>a[i].w;
    }
    sort(a,a+n,cmp);
    int tot=0;
    long long ret=0;
    while(s>=0){
        if(a[tot].h<=(chair+arm)){
            if(a[tot].w<=s){
                ret++;
                s-=a[tot].w;
            }
            else{
                break;
            }
        }
        tot++;
    }
    cout<<ret;
    return 0;
}

|