码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 九度OJ 1433 FatMouse -- 贪心算法


    题目地址:http://ac.jobdu.com/problem.php?pid=1433

    题目描述:

    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.

    输入:

    The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.

    输出:

    For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.

    样例输入:

    5 3
    7 2
    4 3
    5 2
    20 3
    25 18
    24 15
    15 10
    -1 -1

    样例输出:

    13.333
    31.500
    #include 
    #include 
     
    typedef struct fj{
        int food;
        int javabean;
        double rate;
    }FtoJ;
     
    int compare(const void * p, const void * q){
        FtoJ * p1 = (FtoJ *)p;
        FtoJ * q1 = (FtoJ *)q;
        if (p1->rate - q1->rate > 0) return -1;
        if (p1->rate - q1->rate == 0) return 0;
        if (p1->rate - q1->rate < 0) return 1;
    }
     
    int main(void){
        int m, n;
        FtoJ trade[1000];
        int i;
        double sum;
     
        while ((scanf ("%d %d", &m, &n) != EOF) && (m != -1) && (n != -1)){
            for (i=0; i 0 && i= trade[i].food){
                    sum += (double)trade[i].javabean;
                    m -= trade[i].food;
                }
                else{
                    sum += (double)trade[i].javabean * ((double)m / (double)trade[i].food);
                    m = 0;
                }
                ++i;
            }
            printf ("%.3lf\n", sum);
        }
     
        return 0;
    }
  • 相关阅读:
    低代码在物品领用领域数字化转型的案例分析
    【机器学习】--- 深度学习中的注意力机制
    没有几十年功力,写不出这一行“看似无用”的代码!!
    SEBlock | ECABlock | CBAM
    WORD中的表格内容回车行距过大无法调整行距
    1km分辨率逐月降雨量和最高温度数据集(1901-2022)--数据处理
    express学习8-app.use方法
    volatile关键字在并发中有哪些作用?
    进程相关介绍(一)
    离线方式安装高可用RKE2 (版本: v1.22.13+rke2r1)记录
  • 原文地址:https://blog.csdn.net/m0_72345017/article/details/128053000
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号