当前位置:网站首页>*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 类型
边栏推荐
猜你喜欢
随机推荐
元气森林“0糖”背后的百亿推手
汇编语言学习(七)
C语言 指针的解引用详解
汇编语言学习(八)
【翠花学习单例模式】项目框架升级之单例模式及统一异常处理
oracle财务数据权限思考
【视频编码学习】——变换的理解
汇编语言学习(九)
markdown学习1
C语言 一维数组和二维数组的定义及使用
浅谈CQRS模式
RHCE课程总结
openharmony容器组件之Column
阿里巴巴云原生大数据运维平台 SREWorks 正式开源
Xshell建立SSH隧道连接
阿里云发布中国云原生数据湖应用洞察白皮书
flink并行度知识点
汇编语言学习(二)
C语言中常用的数组排序方法:冒泡排序、选择排序、插入排序、数组的移动(含代码详解)以及相关联系题
From the Dutch flag problem to the optimization and upgrade of quick row









