zoukankan      html  css  js  c++  java
  • Lemonade Trade

    4990: Lemonade Trade

    时间限制: 1 Sec  内存限制: 128 MB  Special Judge
    提交: 88  解决: 17
    [提交][状态][讨论版][命题人:admin]

    题目描述

    The lunch break just started! Your mother gave you one litre of pink lemonade. You do not like pink lemonade and want blue lemonade instead. Fortunately for you the other children in class are willing to trade with you.
    Each of them is willing to offer you any quantity of the virtually infinite amount of lemonade they got from their mother, in exchange for their favourite lemonade, according to some exchange rate. The other children are sitting in a long row in the class room and you will walk along the row, passing each child only once. You are not allowed to walk back! Of course, you want to maximise the amount of blue lemonade you end up with. In case you can obtain more than 10 litres of blue lemonade, this is more than you will need, and you will throw away any excess (and keep the 10 litres). 
    Fortunately, you know in advance what everybody is offering for trade. Your task is to write a program to find the maximum amount of blue lemonade that you can obtain.

    输入

    The input consists of the following:
    • One line containing a single integer 0 ≤ N ≤ 105, the number of children in the class room, excluding yourself;
    • N lines, each containing two strings O, W and a floating point number 0.5 < R < 2,the name of the lemonade that is offered, the name of the lemonade that is wanted,and the exchange rate: for every litre of lemonade W that you trade you get R litres of lemonade O in return.
    All strings are guaranteed to have at most 10 alphanumeric characters.

    输出

    Output a single line containing a single floating point number M, the maximum amount (in litres) of blue lemonade that you can obtain. In case you could obtain more than 10 litres, M is considered to be 10. You are required to output M with absolute precision 10−6.

    样例输入

    3
    blue pink 1.0
    red pink 1.5
    blue red 1.0
    

    样例输出

    1.500000000000000
    

    此题关键在于对map的使用及对数的应用和计算指数、对数的相关函数,思路很简单,就是把已经出现过的颜色的最大值记录下来,同时不断新增,更新最大值。

    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    const double eps=1e-8;
    map<string,double>mp;
    int n;
    double r;
    char o[20],w[20];
    int main()
    {
    scanf("%d",&n);
    mp["pink"]=0.0;
    for(int i=0;i<n;i++)
    {
    scanf("%s %s %lf",o,w,&r);
    r=log10(r);
    if(!mp.count(w))
    {
    continue;
    }
    if(!mp.count(o))
    {
    mp[o]=mp[w]+r;
    }
    else
    {
    mp[o]=max(mp[o],mp[w]+r);
    }
    }
    double ans=mp["blue"];
    if(ans-1.0>=eps)
    {
    ans=10.0;
    printf("%.15lf ",ans);
    }
    else if(ans==0)
    {
    printf("%.15lf ",ans);
    }
    else
    {
    printf("%.15lf ",pow(10.0,ans));
    }
    return 0;
    }

  • 相关阅读:
    C# 斐波拉契数列
    Visual Studio [即时窗口] & [命令窗口] (Immediate Window & Command Window) 转
    在.NET平台下 有哪些数据持久层框架 (转)
    WebPart 控件之间通讯 笔记
    WebPart的数据库连接问题 转
    C 语言函数要先声明后定义
    C#单例模式的三种写法(转)
    WCF 绑定wshttpbinding
    关于C#中派生类调用基类构造函数的理解 base使用
    ThinkPHP3.* 模型操作相关函数
  • 原文地址:https://www.cnblogs.com/lglh/p/9068155.html
Copyright © 2011-2022 走看看