大佬求助,贪心60分代码

P1478 陶陶摘苹果(升级版)

likztime @ 2018-01-29 16:58:03

最后的power-tty[i].yi<0不知道怎么写了!

#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<set>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const int F=5000+5;
struct ff {
     int xi;//苹果高度
     int yi;//摘这个苹果所需要的力气
     double llo;//摘单位高度苹果所需要的力气
} tty[F];
bool work(ff a,ff b) { //肯定是力气越小摘的越多啊
     return a.llo<b.llo;
}
int n,s,a,b;
int main() {
     scanf("%d%d",&n,&s);
     scanf("%d%d",&a,&b);
     for(int i=1; i<=n; ++i) {
          scanf("%d%d",&tty[i].xi,&tty[i].yi);
          tty[i].llo=tty[i].yi*1.0/tty[i].xi;
     }
     sort(tty+1,tty+1+n,work);
     int apple=0,power=s;
     for(int i=1; i<=n; ++i) {
          if(a+b>=tty[i].xi) {
               if(power-tty[i].yi>=0) {
                    apple++;
                    power-=tty[i].yi;
               }
          }
     }
     printf("%d\n",apple);
     return 0;
}
//60分代码

|