20分 错哪里了

P1478 陶陶摘苹果(升级版)

Super_Railgun @ 2021-01-31 15:14:12

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n,s,a,b,g=0;
    int x[5005],y[5005];
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
        sort(x,x+n);
    while(s>0){
        if(x[i]<=(a+b)){
            g++;
        }
        s-=y[i];
    }
    }
    cout<<s;
}

by Meatherm @ 2021-01-31 15:26:54

好别致的大括号写法 /jy


by caramel_qwq @ 2021-01-31 15:29:32

你看看我的【别抄,我故意改了几处】

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int ans=0,s,n;
int high,b;
struct apples{
    int y;
    int x;
};
apples a[5005];
bool pd(apples a1,apples a2){
    if(a1.y<a2.y){
        return true;
    }else{
        return false;
    }
}
int main(){
    cin>>n>>s;
    cin>>high>>b;
    for(int i=1;i<n;i++){
        cin>>a[i].x>a[i].y;
    }
    sort(a+1,a+n+2,pd);
    for(int j=1;j<=n;j++){
        if(a[j].x>high+b){
            continue;
        }
        if(s<a[j].y){
            break;
        }
        ans++;
        s-a[j].y;
    }
    printf("%d\n",ans);
    return 0;
} 

by 小超手123 @ 2021-08-13 21:20:34

#include<bits/stdc++.h>
using namespace std;
struct apple{
    int h,m; //高度,力气 
}a[5001];
int n,s;
int hz;
bool cmp(apple x,apple y){
    return x.m < y.m; //把力气值从小到大排序 
}
int main() {
    cin>>n>>s;
    int aa,bb;
    cin>>aa>>bb;
    hz=aa+bb;
    for(int i=1;i<=n;i++)
        cin>>a[i].h>>a[i].m;
    sort(a+1,a+n+1,cmp);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i].h<=hz && a[i].m<=s){
            s-=a[i].m;
            ans++;
        }
        if(a[i].m>s)break;
    }
    cout<<ans;
    return 0; 
}

|