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\n",ans);
}
else if(ans==0)
{
printf("%.15lf\n",ans);
}
else
{
printf("%.15lf\n",pow(10.0,ans));
}
return 0;
}

Lemonade Trade的更多相关文章

  1. 2017 Benelux Algorithm Programming Contest (BAPC 17) Solution

    A - Amsterdam Distance 题意:极坐标系,给出两个点,求最短距离 思路:只有两种方式,取min  第一种,先走到0点,再走到终点 第二种,走到同一半径,再走过去 #include ...

  2. gym101666题解

    A Amsterdam Distance 题意 求圆环上的两点距离. 分析 显然是沿半径方向走到内圈再走圆弧最短. 代码 #include <bits/stdc++.h> using na ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  6. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  7. HDU 3401 Trade dp+单调队列优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...

  8. 【HDU 1009】FatMouse' Trade

    题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...

  9. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. UVa 10213 How Many Pieces of Land ? (计算几何+大数)欧拉定理

    题意:一块圆形土地,在圆周上选n个点,然后两两连线,问把这块土地分成多少块? 析:这个题用的是欧拉公式,在平面图中,V-E+F=2,其中V是顶点数,E是边数,F是面数.对于这个题只要计算V和E就好. ...

  2. E20190523-h

    evaluate v. 估计; 评价; 评估; substantial  adj. 大量的; 价值巨大的; 重大的; 大而坚固的; 结实的; 牢固的; portion n. 部分; (食物的) 一份, ...

  3. QMYSQL driver not loaded 的原理和解决办法

    转:http://blog.csdn.net/m15814478834/article/details/49902077 最近使用Qt遇到了"QMYSQL driver not loaded ...

  4. B-Tree深入理解

    定义: 根节点至少包括两个孩子 树中每个节点最多含有m个孩子(m>=2) 除根节点和叶子节点外,其他每个节点字少有(ceil(m/2):去上线),个孩子. 所有叶子节点都位于同一高度 假设每个非 ...

  5. 深入V8引擎-Time模块介绍

    积跬步,行千里,先从最简单的开始写. 这一篇介绍V8中的时间模块,与libuv粗糙的update_loop_time方法不同,V8有一套独立完整的类负责管理时间. 该类位于src/base/platf ...

  6. Ant Design中的Form组件

    1. 使用Form.create()包裹过的组件可以获取到this.props.form属性 Form.create()(Comp) 2. getFieldDecorator() // 在表单中的使用 ...

  7. php对数组操作的函数

    array_reverse  以相反的顺序返回数组 array_unique 数组元素去重(只对一维数组有效) array_intersect两个或多个数组取交集   implode和explode也 ...

  8. [洛谷P4315] 月下”毛景“树

    题目链接: 点我 题目分析: 树剖.将边权下放到下方点上(为什么要选深度更深的点?一个父亲可能对应多个儿子,但一个儿子只有一个父亲,即可以保证每个点只保存一条边权)成为经典点权+树剖裸题 注意链计算时 ...

  9. 我所接触到的JWT

    名称:JWT--->Json Web Token 用途:客户端请求服务端API时的认证方式之一 用法: 优点: 体积小(一串字符串),因而传输速度快 支持跨域验证,多应用于单点登录 传输方式多样 ...

  10. NET Core 2.1 Preview 1

    NET Core 2.1 Preview 1 [翻译] .NET Core 2.1 Preview 1 发布 原文: Announcing .NET Core 2.1 Preview 1 今天,我们宣 ...