洛谷 P1478 陶陶摘苹果(升级版)C语言

本文提供了一种解决洛谷P1478问题的编程方案,通过直接使用暴力求解的方法来实现。代码中包含了输入、排序及核心逻辑处理过程。

题目来源:https://www.luogu.org/problemnew/show/P1478

直接使用暴力求解即可。

Talk is cheap,show me the code

void cin(int a[][2],int n)
{
    int i;
    for(i=0;i<n;i++)
        scanf("%d%d",&a[i][0],&a[i][1]);
}
void sort_min(int a[][2],int n)
{
    int i,j,t,l;
     for(i=0;i<n-1;i++)
        for(j=0;j<n-i-1;j++)
            if(a[j][1]>a[j+1][1])
                for(l=0;l<2;l++)t=a[j][l],a[j][l]=a[j+1][l],a[j+1][l]=t;
}
int main()
{
    int n,s,heigh;
    int a,b;
    int ap[50000][2];
    int count=0,i=0;
    scanf("%d%d",&n,&s);
    scanf("%d%d",&a,&b);
    cin(ap,n);
    sort_min(ap,n);
    heigh=a+b;
    while(s>0&&i<n)
    {
       if(ap[i][0]<=heigh)
       {
           s-=ap[i][1],count++;
       }
       if(s<0)s+=ap[i][1],count--;
       i++;
    }
    printf("%d",count);
    return 0;




}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值