hdu 1009--greedy
来源:互联网 发布:皇图时装进阶数据 编辑:程序博客网 时间:2024/06/05 13:32
/** \brief hdu 1009--greedy * * \param date 2014/7/18 * \param state AC * \return * */#include <iostream>#include <fstream>#include <algorithm>#include <cstring>using namespace std;const int MAXN=1001;struct Data{ int J; int F; /* bool operator < (const Data& d) const { return d. } */ double price;};Data data[MAXN];bool Comp(const Data& a,const Data& b){ if(a.price>=b.price) return true; else return false;}//void Knapsack(int n,int m,int v[],int w[],int x[])void Knapsack(int n,int m){ //Sort(data,data+n,Comp); sort(data,data+n,Comp); int i; int c=m; double sum=0.0; for(i=0;i<n;i++) { if(c>=data[i].F) { c-=data[i].F; sum+=data[i].J; } else { sum+=c*1.0/data[i].F*data[i].J; c=0; } } printf("%.3f",sum); cout<<endl;}int main(){ //freopen("input.txt","r",stdin); int M,N; while(scanf("%d%d",&M,&N)!=EOF) { if(M==-1 && N==-1)break; for(int i=0;i<N;i++) { //cin>>J[i]>>F[i]; cin>>data[i].J>>data[i].F; data[i].price=data[i].J*1.0/data[i].F; } // Knapsack(N,M); } return 0;}
0 0
- hdu 1009--greedy
- hdu 1009 FatMouse' Trade (Greedy)
- Greedy? HDU
- hdu 4221Greedy?
- hdu 1338 #greedy
- HDU 4380 - Farmer Greedy
- HDU 4221 Greedy?
- hdu 4221 Greedy?
- HDU 4221 Greedy?
- hdu 1052 (greedy algorithm)
- 贪心--HDU - 4221 Greedy?
- HDU 4380 Farmer Greedy
- hdu Greedy 4221 (贪心)
- HDU 4221 Greedy?
- HDU 4221 Greedy?(贪心)
- HDU--4221--Greedy?
- hdu 3916 Sequence Decomposition Greedy
- HDU 4221 Greedy?(贪心)
- 开启我的CSDN博客之旅。
- linux+arm 编译内核
- 2-12. 两个有序链表序列的交集(20)
- 第一课 MVC结构和Struts简介
- TextArea提交表单后显示的内容前出现大段的空格问题
- hdu 1009--greedy
- linux vi 搜索功能的使用
- Android开发之旅:环境搭建及HelloWorld
- 【CodeForces】240F - TorCoder 线段树
- dfghdfgdfgdgdfgdfg
- 【HNOI2004】打砖块
- Xcode快捷键
- 东汉的地理
- Amoeba在CentOS6.5下的安装部署