当前位置:网站首页>*1-3 OJ 291 The mouse and cat trade
*1-3 OJ 291 The mouse and cat trade
2022-08-09 14:48:00 【Ye Xiaobai】
题目描述

输入

输出

样例输入

样例输出

源代码
#include <stdlib.h>
#include <stdio.h>
int main()
{
int m;
int n;
int k;
int i;
int a[1001],b[1001];
double sum=0;
double p[1001]; //
double max = 0;
while(scanf("%d %d",&m,&n)&&m!=-1&&n!=-1)
{
sum=0; //
for(i=0;i<n;i++)
{
scanf("%d %d",&a[i],&b[i]);
p[i]=(double)a[i]/b[i];
}
while(m!=0&&n!=0)
{
max=0;
for(i=0;i<n;i++)
{
if(p[i]>max)
{
max=p[i];
k=i;
}
}
if(m-b[k]>=0)
{
m=m-b[k];
sum+=a[k];
p[k]=0;
}
else
{
sum+=(double)p[k]*m;
m=0;
}
}
printf("%.3lf\n",sum);
}
return 0;
}
关于这题
For optimal solution 就要知道 在一个房间中 Meet one of the cat can get the number of cheese This is a key to the problem solving
m 磅 猫食
n 个 房间
a[i]Each room number of cheese b[i] The demand of cat
p[i] 在一个房间中 Meet one of the cat can get the number of cheese
k Marked which one room
max Compare which one room Meet a cat can get the maximum number of cheese
注:在计算除法时 要转double 类型
边栏推荐
猜你喜欢
随机推荐
源码编译安装LAMP
【LeetCode】1413. 逐步求和得到正数的最小值
图解LeetCode——1413. 逐步求和得到正数的最小值(难度:简单)
“未来10年,中国APP不可能回印度了”
C语言中的 递归问题 以及将递归改写成非递归。(解析常见的几个递归题目及代码) 求阶乘、求斐波那契、汉诺塔、
去IOE-EBS何去何从
小程序开发制作成本是多少?三种开发方法成本分析!
网站小程序开发有哪些步骤?
iptables防火墙
11.cuBLAS开发指南中文版--cuBLAS中的Level-1函数amax()和amin()
汇编语言学习(三)
C语言 求一个整数存储在内存中的二进制中1的个数(多种方法详解)
Jetpack Compose - the use of Image (picture)
网安学习-应急响应3
【ICDE 2022】阿里发布稀疏模型训练框架HybridBackend,单位成本下训练吞吐提升至5倍
汇编语言学习(六)课程设计一
青蛙跳台阶
Jetpack Compose——Image(图片)的使用
递归实现汉诺塔问题
湖仓一体,Hologres加速云数据湖DLF技术原理解析









