hdu FatMouse' Trade
来源:互联网 发布:phpstudy配置虚拟域名 编辑:程序博客网 时间:2024/06/05 17:47
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.
5 37 24 35 220 325 1824 1515 10-1 -1
13.33331.500
#include"stdio.h"#include"math.h"int main (){int m,n;//表示我有的猫粮 和房间数 int f[20][2];// 豆 猫粮 int i,j;//计数器 double max; //表示可以得到的最多的豆 double bili[20],bili3;// 猫粮/豆 的比值 int chucunqi1, chucunqi2;//储存器 scanf("%d%d",&m,&n);while(m!=-1&&n!=-1){for(i=0;i<n;i++) { scanf("%d%d",&f[i][0],&f[i][1]);//将每个房间内 豆的的量 和 最多要的猫粮 bili[i]=1.0*f[i][1]/f[i][0]; } for(i=0;i<(n-1);i++) { for(j=0;j<(n-1-i);j++) { if(bili[j+1]<bili[j]) { bili3=bili[j]; bili[j]=bili[j+1]; bili[j+1]=bili3; chucunqi1=f[j][0]; f[j][0]=f[j+1][0]; f[j+1][0]=chucunqi1; chucunqi2=f[j][1]; f[j][1]=f[j+1][1]; f[j+1][1]=chucunqi2; }//一但前者比例值大于后者 立马将数的位置互换 } }//这里结束后应该会使新一轮的bili比值比从小到大 for(i=0;i<n;i++) { for(j=0;j<2;j++) { printf("%d ",f[i][j]);}printf("\n");} for(i=0;i<n;i++) { max=0; m=m-f[i][1]; if(m<=0) { for(j=0;j<i;j++) { max=max+f[j][0]; } if(m<0) { max=max+(m+f[i][1])*1.0*f[i][0]/f[i][1]; //m=m+f[i][1]; break; } if(m=0) { max=max+f[i][0]; //m=m+f[i][1]; break; } } } //第二次循环居然没有排序了 还是一开始就没有排序了? printf("%0.3lf",max); scanf("%d%d",&m,&n);}return 0;}
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 - FatMouse' Trade
- HDU-1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU--1009--FatMouse' Trade
- hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU-1009 FatMouse' Trade
- axis 2调用webservice
- 【TensorFlow】模型持久化tf.train.Saver—上(八)
- 第3章 NVIDIA Jetson TK2优化配置
- Java集合之ConcurrentHashMap源码分析
- Android自适应不同屏幕几种方法
- hdu FatMouse' Trade
- jquery之on()和click()的本质区别
- UEFI/GPT分区结构
- Python3之不使用第三方变量,交换两个变量的值
- SVG 基本图形
- Spring 定时任务之 @Scheduled cron表达式
- Python词云图绘制—看博客大佬们的写作热点
- AngularJs讲师排序方法
- CUDA获取错误信息