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;
    }

  • 相关阅读:
    WINCE6.0 error C2220: warning treated as error问题解决
    GPRS连接失败问题
    wince下sourcessources.cmnMakefile.def的相关作用
    IMX515开发备忘
    WINCE补丁包下载地址
    IMX51+WINCE6.0平台缩写意义
    喵哈哈村的魔法考试 Round #1 (Div.2) ABCD
    Codeforces Round #402 (Div. 2) D
    Codeforces Round #402 (Div. 2) C
    Codeforces Round #402 (Div. 2) B
  • 原文地址:https://www.cnblogs.com/lglh/p/9068155.html
Copyright © 2011-2022 走看看