Greedy——HDOJ 1203
来源:互联网 发布:医学生常用的软件 编辑:程序博客网 时间:2024/06/03 23:21
HDOJ 1203 题目描述
/*HDOJ 1203典型的贪心,类似于01背包和部分背包的中间类型*/#include <iostream>#include <iomanip>#include <algorithm>using namespace std;struct School{int a; //申请费用double b; //录取概率double scale; // b/a};bool cmp(const School &a,const School &b){return (a.scale > b.scale); //按照scale降序排序}int main(){School of[1000],su[1000];int n,m,k;double success;while(cin>>n>>m){if((n == 0) && (m == 0))break;for(int i=0;i<m;i++){cin>>of[i].a>>of[i].b;of[i].scale=of[i].b/of[i].a;}sort(of,of+m,cmp);success=1.0;k=0;for(i=0;i<m;i++){if(n >= of[i].a){n-=of[i].a;su[k]=of[i];k++;}}for(i=0;i<k;i++)success *= (1-of[i].b);success=(1-success)*100;cout<<setiosflags(ios::fixed);cout<<setprecision(1)<<success<<"%"<<endl;}return 0;}
- Greedy——HDOJ 1203
- Greedy——HDOJ 1009
- Greedy——HDOJ 2037
- Greedy——HDOJ 1050
- Greedy——HDOJ 1052
- Greedy——HDOJ 1789
- Greedy——HDOJ 1051
- hdoj 4221 Greedy?
- Greedy——活动选择问题
- greedy——455. Assign Cookies
- 算法14讲——MST/Greedy
- hdoj 4976 A simple greedy problem.【dp】
- 【DP】 HDOJ A simple greedy problem.
- Greedy
- Greedy
- Greedy
- USACO——Greedy Gift Givers 贪婪的送礼者
- greedy——435. Non-overlapping Intervals[medium]
- 线程事件对象之CreateEvent的用法
- Android定位功能(一)
- Android定位功能(二)
- 一个简单的HTML标签搞死Win7
- .NET远程处理(Remoting)与WCF的性能对比
- Greedy——HDOJ 1203
- 学历是什么?
- 使用sql建库脚本创建数据库
- Java中的finalize()方法详解
- Oracle 数据库关闭 FAQ
- 创建并调用MFC规则DLL的实例
- android java获取当前时间的总结
- soap概念,HTTP + XML = SOAP
- BeanUtils工具包操作JavaBean