蛇皮 @ 2020-01-19 10:50:36
#include<stdio.h>
#include <stdlib.h>
typedef struct pingguo
{
int x;
int y;
}apple;
apple k[5001];
int cmp(const void*p,const void*q)
{
return (*(apple *)p).y - (*(apple *)q).y;
}
int main()
{
int num=0;
int n,s,a,b;
int h=a+b;
scanf("%d %d",n,s);
scanf("%d %d",a,b);
for(int i=0;i<n;i++)
{
scanf("%d%d",k[i].x,k[i].y);
}
qsort(k,n,sizeof(apple),cmp);
for(int i=0;i<n;i++)
{
if(k[i].x<=h&&k[i].y<=s)
{
num++;s-=k[i].y;
}
}
printf("%d",num);
}
by Rainy7 @ 2020-01-19 10:51:32
@蛇皮 scanf没加&
by 蛇皮 @ 2020-01-19 11:21:22
@Rainy7 加了之后,发现我的qsort用了排序出来的结果是错的,求大佬指教
by Mkarry @ 2020-01-19 11:24:38
干嘛用qsort,sort它不香么
by 蛇皮 @ 2020-01-19 11:40:02
@Mkarry c语言不能用sort,我不能用c++也是很无奈
by ddgtang @ 2020-01-19 12:56:30
你可以一边输入一边判断啊