只对 4,大佬求助

P1478 陶陶摘苹果(升级版)

wzrybaicun @ 2021-05-13 17:01:29

#include <bits/stdc++.h>
using namespace std;
int a,b;
int n,s;
int i,j;
int cnt=0;
struct Pg
{
    int x;
    int y;
    double yx;
}pg[5001];

bool cmp(Pg e,Pg f)
{
    return e.yx<f.yx;
}

int main()
{
    scanf("%d%d",&n,&s);
    scanf("%d%d",&a,&b);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&pg[i].x,&pg[i].y);
        pg[i].yx=double(pg[i].y/pg[i].x);
    }
    sort(pg+1,pg+n+1,cmp);
    b+=a;
    for(i=1;i<=n;i++)
    {
        if(pg[i].x<=b&&pg[i].y<=s)
        {
            s-=pg[i].y;
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
} 

by HYdroKomide @ 2021-05-13 18:56:42

@wzrybaicun 应该把力气从小到大排序,然后从中循环并找到可以摘下的苹果


by HYdroKomide @ 2021-05-13 18:58:28

@wzrybaicun

#include <bits/stdc++.h>
using namespace std;
int a,b;
int n,s;
int i,j;
int cnt=0;
struct Pg
{
    int x;
    int y;
}pg[5001];

bool cmp(Pg e,Pg f)
{
    return e.y<f.y;
}

int main()
{
    scanf("%d%d",&n,&s);
    scanf("%d%d",&a,&b);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&pg[i].x,&pg[i].y);
    }
    sort(pg+1,pg+n+1,cmp);
    b+=a;
    for(i=1;i<=n;i++)
    {
        if(pg[i].x<=b&&pg[i].y<=s)
        {
            s-=pg[i].y;
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
} 

就A了


by wzrybaicun @ 2021-05-15 15:33:39


by kiki5 @ 2021-06-19 14:10:00

你个逼逼


by zjaj0201 @ 2021-08-05 14:30:09

@kiki550 怎么还骂人了


by kiki5 @ 2021-08-05 19:30:38

@zjaj0201 逼逼


by zjaj0201 @ 2021-09-05 13:25:09

@kiki550 孺子真他娘可教也!


by kiki5 @ 2022-11-19 20:25:47

@zjaj0201 不是我发的 我的学生发的


by zjaj0201 @ 2023-01-07 20:10:53

@kiki550 ?学生?你是老师???


|