Zirnc @ 2018-09-15 14:36:04
还是二话不说上代码:
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct aApple {
int xi;
int yi;
};
bool cmp(aApple a, aApple b)
{
if (a.yi > b.yi)
{
return 0;
} else if (a.yi < b.yi) {
return 1;
}
if (a.xi > b.xi)
{
return 0;
} else if (a.xi < b.xi) {
return 1;
}
return 0;
}
int main()
{
cout.sync_with_stdio(false);
int n, s;
int a, b;
aApple ar[5001];
cin >> n >> s;
cin >> a >> b;
int sum = 0;
for (int i = 0; i < n-1; i++)
{
cin >> ar[i].xi >> ar[i].yi;
}
sort(ar, ar+n-1, cmp);
//cout << "\n\n";
//for (int i = 0; i < n-1; i++)
//{
//cout << ar[i].xi << " " << ar[i].yi << "\n";
//}
for (int i = 0; i < n-1; i++)
{
if (a+b > ar[i].xi && s >= ar[i].yi)
{
sum++;
s-=ar[i].yi;
}
}
cout << ++sum << endl;
return 0;
}
跪求大佬相助~蟹蟹~
by Zirnc @ 2018-09-17 16:54:08
跪求神犇
by ihan255 @ 2018-09-19 21:42:31
@ChungZH
我这是80分的,希望对您有帮助,虽然我也没AC
#include<iostream>
#include<algorithm>
using namespace std;
int n,s,a,b,x,y,i,k[5005],sum=0;
int main()
{
cin>>n>>s>>a>>b;
a+=b;
for(i=1;i<=n;i++)
{
cin>>x>>y;
if(x<=a) k[i]=y;
}
sort(k+1,k+n+1);
for(i=1;i<=n&&(s-k[i])>=0;i++)
{
if(k[i]==0) continue;
s-=k[i];
sum++;
}
cout<<sum;
return 0;
}
by Zirnc @ 2018-09-21 13:20:19
@wu55555 谢谢大佬,我学习学习
by ihan255 @ 2018-09-23 17:43:14
@ChungZH 什么大佬,我就一小蒟蒻QWQ @文文殿下这位才是大佬
by ihan255 @ 2018-09-23 18:32:43
@文文殿下