第一个测试点过不去,哪位dl能提供一下第一个测试点的信息?

P1478 陶陶摘苹果(升级版)

zhs3202669494 @ 2020-02-11 16:55:43

#include <stdio.h>
#include <stdlib.h>

void sort(int(*)[2],int);
void swap(int**,int**);
void judge(int(*)[2],int,int,int,int);

int main()
{
    int n,s,a,b;
    int i,j;

    scanf("%d%d",&n,&s);
    scanf("%d%d",&a,&b);

    int apples[n][2];

    for(i=0;i<n;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",apples[i]+j);
        }
    }

    sort(apples,n);

    judge(apples,s,n,a,b);

    return 0;
}

void sort(int(*a)[2],int n)
{
    int i,j;

    for(i=0;i<n;i++)
    {
        for(j=1;j<n-i;j++)
        {
            if(a[j][1]<a[j-1][1])
                swap((int**)a+j,(int**)a+j-1);
        }
    }
}

void swap(int**a,int**b)
{
    int*c;

    c=*a;
    *a=*b;
    *b=c;
}

void judge(int(*app)[2],int s,int n,int a,int b)
{
    int i;
    int count=0;

    for(i=0;i<n;i++)
    {
        if(app[i][0]<=a+b)
        {
            s=s-app[i][1];
            if(s<=0)
        {
            break;
        }
            count++;

        }
    }

    printf("%d",count);
}

by qrhao @ 2020-02-11 17:04:49

最好不要用c++内部定义过的函数名


by qrhao @ 2020-02-11 17:10:09

@zhs3202669494


by qrhao @ 2020-02-11 17:23:56

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <functional>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <sstream>
using namespace std;
struct h{
    int g;
    int l;
}shu[5005];
bool cmp(h a,h b)
{
    return a.l < b.l;
}
int main()
{
    int n,s,a,b,sum = 0;
    scanf("%d %d",&n,&s);
    scanf("%d %d",&a,&b);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d %d",&shu[i].g ,&shu[i].l);
    }
    sort(shu + 1,shu + n + 1,cmp);
    for(int i = 1;i <= n;i++)
    {
        if(s - shu[i].l < 0)
        {
            break;
        }
        if((a + b) < shu[i].g) continue;
        sum++;
        s -= shu[i].l;
    }
    printf("%d",sum);
    return 0;
}

by Clintikas97 @ 2020-02-11 17:27:00

C++有内部函数sort,count和swap


by zhs3202669494 @ 2020-02-11 17:31:25

@qiruhao 我这个是C 语言


by zhs3202669494 @ 2020-02-11 17:35:38

@qiruhao 好的,明白你的意思了


by qrhao @ 2020-02-11 17:39:09

你语言识别是c语言吗


by qrhao @ 2020-02-11 17:39:21

@zhs3202669494


by zhs3202669494 @ 2020-02-11 17:41:44

@qiruhao 是的


by Snnnow @ 2020-03-06 22:28:23

第一个测试点 7 6

3140 0

110 1

100 3

127 1

121 1

0 99

130 0

90 6

答案应该是5 他给的.out里写了个4,是不对的,并且4过不了


|