标签:output ott bsp hdu multi single name c++ spec
http://acm.hdu.edu.cn/showproblem.php?pid=1009
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int N, M;
struct Node{
double j;
double f;
double pri;
}node[maxn];
bool cmp(const Node& a, const Node& b) {
return a.pri > b.pri;
}
int main() {
while(~scanf("%d%d", &M, &N)) {
if(N == -1 && M == -1) break;
for(int i = 1; i <= N; i ++) {
scanf("%lf%lf", &node[i].j, &node[i].f);
node[i].pri = node[i].j / node[i].f;
}
double num = 0.0;
sort(node + 1, node + 1 + N, cmp);
for(int i = 1; i <= N; i ++) {
if(M >= node[i].f) {
num += node[i].j;
M -= node[i].f;
}
else {
num += M * node[i].j / node[i].f;
break;
}
}
printf("%.3lf\n", num);
}
return 0;
}
标签:output ott bsp hdu multi single name c++ spec
原文地址:https://www.cnblogs.com/zlrrrr/p/9698243.html