首页 > 其他 > 详细

hdu 2187(贪心)

时间:2014-02-05 13:05:32      阅读:369      评论:0      收藏:0      [点我收藏+]

#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1000 + 10;
int c;
int n, m;

struct Node{
int p;
int h;
}node[maxn];

bool cmp(Node a, Node b){ //升序
return a.p < b.p;
}

int main(){
cin>>c;
while(c--){
cin>>n>>m;
for(int i=0; i<m; i++){
cin>>node[i].p>>node[i].h;
}
sort(node, node + m, cmp);
double sum = 0;
for(int i=0; i<m; i++){
if(n == 0)
break;
if(node[i].p * node[i].h <= n){
n = n - node[i].p * node[i].h;
sum += node[i].h;
}
else{
sum += n * (1.0 / double(node[i].p));
break;
}
}
printf("%.2lf\n", sum);
}
return 0;
}

hdu 2187(贪心)

原文:http://www.cnblogs.com/cbyniypeu/p/3538184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!