蒟蒻求助,只有20qwq

P1478 陶陶摘苹果(升级版)

莫子恺 @ 2018-10-19 18:29:52

跪求各位dalao修改

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,a,b,xi[5001],yi[5001],ki[5001]{0};
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++)
    {
        cin>>xi[i]>>yi[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a+b>=xi[i])
        {
            ki[i]=yi[i];
        }
    }
    sort(ki+1,ki+n+1);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans++;
        s-=ki[i];
        if(s<=0)
        {
            cout<<ans;
            break;
        }
    }
    return 0;
} 

by skiy_gyx @ 2018-10-19 18:38:45

AC程序 参考一下?

#include<bits/stdc++.h>
using namespace std;
int h[10010],v[10010];
int main(){
    int n,s,a,b;
    cin>>n>>s>>a>>b;

    for(int i=1;i<=n;i++){
        cin>>h[i]>>v[i];
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=n-i;j++){
            if(v[j]>v[j+1]){
                swap(h[j],h[j+1]);
                swap(v[j],v[j+1]);
            }
        }
    }
    int t=0;
    for(int i=1;i<=n;i++){
        if(s>=v[i]){
            if(a+b>=h[i]){
                t++;
                s-=v[i];
            }
        }else{
            break;
        }
    }
    cout<<t<<endl;
    return 0;
}       

by sss7020 @ 2018-10-19 18:41:57

参考+1:

#include<iostream>
#include<algorithm>
using namespace std;
struct Stu{
    int xi;
    int yi;
};
Stu a[5005];
bool cmp(Stu t,Stu k){
    return t.yi<k.yi;
}
int main(){
    int n,s,an,b,ans=0;
    cin>>n>>s>>an>>b;
    for(int i=0;i<n;i++){
        cin>>a[i].xi>>a[i].yi;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n&&s>0;i++){
        if(an+b>=a[i].xi&&s>=a[i].yi){
            ans++;
            s-=a[i].yi;
        }
        else if(s<a[i].yi)break;
    }
    cout<<ans<<endl;
    return 0;
}

by 莫子恺 @ 2018-10-19 18:43:02

@gyxAC之神 感谢


by 莫子恺 @ 2018-10-19 18:44:29

@陈博文1412 thanks


by Marginalin @ 2018-10-19 18:50:00

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int N, L, Max=0, Ans=0, cun=0;

struct App {
    int GD, LQ;
}A[5005];

bool my_cmp(const App &a, const App &b) {
    return a.LQ<b.LQ;
}

void solve() {
    scanf("%d%d", &N, &L);
    int a, b;
    scanf("%d%d", &a, &b); Max = Max + a + b;
    for(int i=1; i<=N; i++) {
        scanf("%d%d", &a, &b);
        if(a <= Max) {
            A[++cun].GD = a;
            A[cun].LQ = b;
        }
    }
    sort(A+1, A+cun+1, my_cmp);
    int i = 1;
    while(L>0 && i<=cun) {
        if(A[i].LQ <= L) {
            Ans ++;
            L -= A[i].LQ;
            //cout<<A[i].GD<<' '<<A[i].LQ<<endl;
        }
        i ++;
    }
    cout << Ans;
}

int main() {

    solve();

    return 0;
}

by NaCly_Fish @ 2018-10-19 18:52:27

头像好评


by FifthAxiom @ 2018-10-19 18:55:32

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,a,b,x[5001],y[5001],ans=0,p;
    cin>>n>>s;
    cin>>a>>b; a+=b;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=1;i<n;i++)
      for(int j=i+1;j<=n;j++)
        if(y[i]>y[j]) {
            p=x[i];x[i]=x[j];x[j]=p;
            p=y[i];y[i]=y[j];y[j]=p;    
        }
    for(int i=1;i<=n;i++)
      if(x[i]<=a&&s-y[i]>=0) {ans++;s-=y[i];}
    cout<<ans;
    return 0;
}

by Absurdity @ 2018-10-19 18:55:53

这…………

这可是陶陶摘苹果啊,你竟然…………


by FifthAxiom @ 2018-10-19 18:57:39

我……咋啦


by MZW_BG @ 2018-10-19 19:32:31

有哪位大佬想用网络流搞一下吗?


|