杭电acm2187

#include <stdio.h>
#include <algorithm>

using namespace std;

struct rice {
	double money;
	double weight;
    
    bool operator < (const rice &A) const {
        return money < A.money;
    }
	
}w[1001];


int main() {
	
	int c, n, m, i, ids;
	double ans;
	scanf("%d", &c);
	while(c--) {
		scanf("%d%d", &n, &m);
		for(i=0; i<m; i++) {
			scanf("%lf%lf", &w[i].money, &w[i].weight);
		}
		
		sort(w, w+m);
		
		ids = 0;
		ans = 0;
		while(n && ids<m) {
			if(n>=w[ids].money * w[ids].weight) {
				n -= w[ids].money * w[ids].weight;
				ans += w[ids].weight;
			} else {
				ans += (n * 1.0) / w[ids].money;
				n = 0;
			}
			ids ++;
		}
		
		printf("%.2lf\n", ans);
	}
	
	return 0;
}

posted @ 2015-11-01 17:06  StevenLuke  阅读(116)  评论(0编辑  收藏  举报