日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 1009FatMouse' Trade

發布時間:2024/1/8 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 1009FatMouse' Trade 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

FatMouse' Trade

Time Limit : 2000/1000ms (Java/Other)???Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 50???Accepted Submission(s) : 19

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.

Input

The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.

Output

For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.

Sample Input

5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1

Sample Output

13.333 31.500

Author

CHEN, Yue

Source

ZJCPC2004
Statistic | Submit | Back 大意:老鼠有m磅貓糧,在一個地方有n個房間,每個這里有貓在看守,第i個房間里有j[i]鎊豆子要求f[i]磅貓糧房間里的豆子便可全部帶走,但老鼠不一定要全部帶走,如果老鼠給了貓f[i]*a%磅的貓糧,則他可獲得j[i]*a%磅的豆子,求老鼠可獲得的最大數量的豆子是多少? 思路:問題相當于買東西,如何花最少的錢來買最近可能多的東西。所以那件東西花的錢(貓糧)最少就先買哪一個,也就是說花同樣的錢(貓糧),哪個買的多就先買哪個。 即先買j[i]/f[i]最大的那個,若不貓要求的貓糧,則就買m/f[i]*j[i]的豆子。可先將j[i]/f[i]排序,再從最多的往下買 代碼: #include <iostream> #include<iomanip> #define MAX 9999999 using namespace std; double j[1000],f[1000],p[1000]; void order(double p[],double j[],double f[],int n) {int i,s,k;for(i=n; i>0; i--){k=0;for(s=0; s<i; s++){if(p[k]>=p[s]){k=s;}}double t;t=p[k];p[k]=p[i-1];p[i-1]=t;t=j[k];j[k]=j[i-1];j[i-1]=t;t=f[k];f[k]=f[i-1];f[i-1]=t;} } int main() {int n,i; double s,m;while(cin>>m>>n&&(n!=-1&&m!=-1)){s=0;for(i=0; i<n; i++){cin>>j[i]>>f[i];if(f[i]!=0)//分母等于零的情況處理p[i]=j[i]/f[i];elsep[i]=MAX;//max假定無窮}order(p,j,f,n);//排序for(i=0; i<n; i++){if(m>=f[i])//足夠付得起{s=s+j[i];m=m-f[i];}else if(m>=0&&m<f[i])付不起時{s=s+m*p[i];m=0;}}cout<<setiosflags(ios::fixed)<<setprecision(3);cout<<s<<endl;}return 0; }

總結

以上是生活随笔為你收集整理的HDU 1009FatMouse' Trade的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。