ACM
来源:互联网 发布:数据归一化后的值 编辑:程序博客网 时间:2024/06/07 13:56
杭电1.3.1
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.
#include <stdio.h>int main(){int N,i,j;double temp = 0;double M;int out[1002];int get[1002];double og[1002];while(scanf("%lf%d",&M,&N) ){if(M == -1 && N == -1){break;}for(i=0; i<N; i++){scanf("%d%d",&get[i],&out[i]);if(out[i] == 0){og[i] = 100001.0;}else{og[i] = get[i] * 1.0 / out[i];}}for(i=0; i<N-1; i++){for(j=i+1; j<N; j++){if(og[i] < og[j]){temp = og[i];og[i] = og[j];og[j] = temp;temp = get[i];get[i] = get[j];get[j] = temp;temp = out[i];out[i] = out[j];get[j] = temp;}}}double sum = 0;temp = 0;for(i=0; i<N; i++){temp = temp + out[i];sum = sum + get[i];j = i;if(temp > M){sum = sum - get[i]; //减去最后一个房子,因为最后一个房子不能全部兑换break;}}sum = sum + (M - (temp - out[j])) * og[j];printf("%.3lf\n",sum);}return 0;}
0 0
- ACM
- acm
- ACM
- acm
- ACM!!
- ACM!!
- acm
- ACM
- ACM
- acm
- acm
- ACM
- ACM
- ACM
- ACM
- ACM
- ACM
- ACM
- Github入门教程
- 利用随机数函数生成 6 个字符,依次拼接到“Words:”字符串的末尾, 并输出该字符串的长度,大写英文字母的个数。
- 窗口的子类化与超类化
- 快速排序
- LeetCode *** 228. Summary Ranges
- ACM
- 关于MFC中添加对话框类后类视图(class view)无显示
- STM32初学之Sys_Tick配置
- 基于sklearn的特征选择方法
- 扩展GCD
- 认识vim
- 如果链表可能有环,判断两个链表是否相交?
- 16.Java IO: PipedOutputStream && Java IO: PipedOutputStream
- Java-单机版的书店管理系统(练习设计模块和思想_系列 二 )