# HDU 1009 FatMouse' Trade （贪心算法）

```#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#include <cctype>

using namespace std;
struct node{
double ave;   int x, y;
node() { }
node(int xx, int yy) : x(xx), y(yy), ave((double)xx/(double)yy) { }
bool operator < (const node &p) const {
return ave > p.ave;
}
};
node a[1005];

int main(){
int n, m;
while(~scanf("%d %d", &n, &m) && (m+n != -2)){
int x, y;
for(int i = 0; i < m; ++i){
scanf("%d %d", &x, &y);
a[i] = node(x, y);
}

sort(a, a+m);
double ans = 0.0;
for(int i = 0; i < m; ++i){
if(n >= a[i].y){ ans += a[i].x;  n -= a[i].y;  }
else if(!n)  break;
else{
ans += a[i].ave * n;
n = 0;
}
}
printf("%.3lf\n", ans);
}
return 0;
}
```

### HDU 1009 FatMouse' Trade （贪心算法）的相关文章

FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and req

## 【贪心专题】HDU 1009 FatMouse&#39; Trade （贪心选取）

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pound

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 59851    Accepted Submission(s): 20095 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats gu