求错,在线等

P1478 陶陶摘苹果(升级版)

fzhfzh @ 2019-05-13 18:59:50

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,s,a,b,cnt=0;
    cin>>n>>s>>a>>b;
    int high[n],liqi[n];
    for(int i=0;i<n;i++){
        cin>>high[i]>>liqi[i]; 
    }
    sort(liqi,liqi+n);
    for(int i=0;;i++){
        if(s<liqi[i])break;
        else if(high[i]<=a+b&&s>=liqi[i]){
            cnt++;
            s-=liqi[i];
        }
    }
    cout<<cnt;
    return 0;
}

by 御·Dragon @ 2019-05-13 19:04:50

@fzhfzh 先把码风该漂亮了再说


by DARKSTALKING @ 2019-05-13 19:05:36

在读入高度和力气的情况下, 必须要判断可以摘到啊


by fzhfzh @ 2019-05-13 19:05:45

@封禁用户名f8617dda 什么意思


by DARKSTALKING @ 2019-05-13 19:06:28

这码风有什么奇怪的吗


by fzhfzh @ 2019-05-13 19:06:29

@DARKSTALKING 写地下了


by DARKSTALKING @ 2019-05-13 19:06:48

@fzhfzh 意思就是写代码的格式啦


by fzhfzh @ 2019-05-13 19:07:38

测试点四: 输入:0 0 0 0 输出:0 我用我的代码测试后输出的也是0呀?


by fzhfzh @ 2019-05-13 19:07:50

@DARKSTALKING


by DARKSTALKING @ 2019-05-13 19:08:14

#include<bits/stdc++.h>
using namespace std;
int n,power,a,b,sum,num[5005],ans;
int main()
{
    cin>>n>>power>>a>>b;
    int f=0;
    for(int i=0;i<n;i+=1)
    {
        int high,need;
        cin>>high>>need;
        if(high<=a+b)
        {
            num[f]=need;
            f+=1;       
        }   
    }
    sort(num,num+f);
    for(int i=0;i<n;i+=1)
    {
        if(num[i]+sum>power)
            break;
        if(num[i]+sum<=power)
        {
            ans+=1;
            sum+=num[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

by DARKSTALKING @ 2019-05-13 19:09:14

@fzhfzh 不知道,我有时也有这样的问题


| 下一页