当前位置:网站首页>*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 类型
边栏推荐
猜你喜欢

Jetpack Compose - the use of Image (picture)

SEATA分布式事务框架解析

Analysis of SEATA Distributed Transaction Framework

响应式pbootcms模板建材家居类网站

Three kinds of ThreadLocal, play with thread variable storage and transmission

*1-1 OJ 56 Hamming Distance

去IOE-EBS何去何从

display:inline-block 什么时候不会显示间隙?

阿里巴巴云原生大数据运维平台 SREWorks 正式开源

*3-1 CCF 2014-09-1 相邻数对
随机推荐
关于舵机的漂移与不听指挥乱动的问题
spark单机版安装
*4-2 CCF 2014-12-2 Z字形扫描
iptables防火墙
*4-1 CCF 2014-12-1门禁系统
Jetpack Compose——Image(图片)的使用
*5-1 CCF 2015-03-1 图像旋转
12.cuBLAS开发指南中文版--cuBLAS中的Level-1函数asum()和axpy()
C语言 最大公约数,最小公倍数(详细注释代码 一次解决)
Xshell建立SSH隧道连接
*3-4 CCF 2014-09-3 字符串匹配
C语言 一维数组和二维数组的定义及使用
Flex for openharmony container components
C语言 指针的解引用详解
typeorm 批量插入数据优化和插入冲突操作
响应式pbootcms模板建材家居类网站
shell课程总结
三子棋的代码实现
C语言中的运算符(超全超详细)
阿里巴巴云原生大数据运维平台 SREWorks 正式开源