HDOJ1009
2016-05-26 20:10
246 查看
#include"iostream" #include"algorithm" using namespace std; struct job { double j; double c; friend bool operator<(job&a,job&b) { return a.j/a.c>b.j/b.c; } }; int main() { //freopen("a.txt","r",stdin); int n,m; while(cin>>n>>m&&n!=-1&&m!=-1) { job a[1000]; int i; for(i=0;i<m;i++) scanf("%lf%lf",&a[i].j,&a[i].c); sort(a,a+m); double sum=0; double space=n; for(i=0;i<m;i++) { if(space>0) { if(space-a[i].c>=0) { sum+=a[i].j; space=space-a[i].c; continue; } if(space-a[i].c<0) { double st=space/a[i].c*a[i].j; //cout<<st<<endl; sum+=st; space=0; } } if(space==0) break; } printf("%.3f\n",sum); } return 0; }
相关文章推荐
- 根据li标签 查找class="alcw4 alcw41"对应的值
- Maven nexus私服安装
- mybatis系列-08-动态sql
- sk_buff属性详解
- 我又回来啦!!!!
- 根据li标签 查找class="alcw4 alcw41"对应的值
- 根据li标签 查找class="alcw4 alcw41"对应的值
- Oracle 对表设置并行度对执行计划的影响
- Java IO - FilterInputStream&FilterOutputStream
- iOS简单、方便、好用的HZSigmentView
- eclipse+spket+Extjs4.2.1开发环境搭建
- Binary Tree Zigzag Level Order Traversal 二叉树ZigZag打印
- eclipse+spket+Extjs4.2.1开发环境搭建
- Restful based service 的跨域调用
- oracle数据库的常用命令
- BZOJ3771 Triple
- C++ STL--stack/queue 的使用方法
- 数据结构 第十章 内部排序之插入排序
- Hust oj 2235 毒(水题)
- 对象(深入C++对象模型)