Colin_Lovecraft @ 2018-08-29 21:59:28
这有什么问题吗?为什么只得40分。
#include<iostream>
#include<algorithm>
using namespace std;
struct apple{
int xi;
int yi;
}xxx[1005];
bool cmp(apple a,apple b)
{
return a.yi<b.yi;}
int main(){
int n,s,a,b;
cin>>n>>s>>a>>b;
int i,x,y,k=0;
int ans=0;
for( i=0;i<n;i++)
{
cin>>x>>y;
if(x<=a+b)
{
xxx[k].xi=x;
xxx[k].yi=y;
k++;
}
}
sort(xxx,xxx+n,cmp);
for(i=0;i<n;i++)
{
if(s>=xxx[i].yi)
{
s=s-xxx[i].yi;
ans++;
}
}
cout<<ans;
return 0;
}
by Stephzzz @ 2018-08-29 22:21:25
#include<bits/stdc++.h>
using namespace std;
int n,a,b,s,ans=0;
struct aa
{
int high;
int power;
} f[5001] ;
bool operator < ( aa b,aa tmp)
{
return b.power<tmp.power;
}
int main()
{
cin>>n>>s;
cin>>a>>b;
for (int i=1;i<=n;i++)
{
scanf("%d%d",&f[i].high,&f[i].power);
}
sort(f+1,f+n+1);
int big=a+b;
for (int i=1;i<=n;i++)
{
if (s>=f[i].power && f[i].high<=big)
{
s=s-f[i].power;
ans++;
}
}
cout<<ans;
return 0;
}
by Colin_Lovecraft @ 2018-08-30 08:13:07
那个排序函数你怎么没用?