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. 超级实用的Chrome插件

    1.JSON-handle:浏览器前台访问后台,后台返回json,它帮你格式化 2.Page Ruler:帮你测量页面上任何位置的长宽高 3. Momentum:打开新的tab页就像打开了一个新的世界 ...

  2. 51nod1117【贪心】

    思路:哈夫曼树~~哇塞,那么有道理. 利用堆维护:每次从堆里取两个最小加起来,然后还是最小的两个,最后只剩一根总的 #include <bits/stdc++.h> using names ...

  3. RenderTexture

    https://docs.unity3d.com/Manual/class-RenderTexture.html Size: 图片像素尺寸,这个size可以直接在脚本里通过width和height动态 ...

  4. codeforces358D Dima and Hares【dp】

    从本质入手,这个东西影响取值的就是相邻两个哪个先取 设f[i][0/1]为前i个(i-1,i)中先取i/i-1的值(这里不算上i的贡献 转移就显然了,注意要先复制-inf #include<io ...

  5. nginx反向代理解决跨域问题,使本地调试更方便

    我们可能都会遇到一个这样的问题,线上环境是https://...,本地启动了项目,域名是localhost:8000等,本地想要访问线上的接口,直接在本地调试,却提示跨域,这个时候我们可以配置ngin ...

  6. String,StringBuffer和StringBuilder

    String,StringBuffer和StringBuilder分别应该在什么情况下使用? String 是Java的字符串类,其实质上也是用Char类型存储的,但是除了hash属性,其他的属性都声 ...

  7. javascript中的style只能取到在HTML中定义的css属性

    如果在css中定义的 li{ width:100px; left:100px; top:; position:absolute; font-style:normal; } 这样执行: oli[0].s ...

  8. Codeforces 1105D(双层广搜)

    要点 题意:可以拐弯,即哈密顿距离 注意不可以直接一个一个搜,这过程中会把下一轮的标记上,导致同一轮的其它点没能正常完成应有的搜索 因此采用双层广搜,把同一轮先都出队列再的一起搜 #include & ...

  9. Net Core IIS Express In

    IIS Express In Asp.Net Core   IIS Express是一个Mini版的IIS,能够支持所有的Web开发任务,但是这种设计有一些缺陷,例如只能通过localhost:< ...

  10. CSS——制作天天生鲜登陆页面

    这个登陆页面主要是有一个form表单,其他的和首页差不多的. login.html: <!DOCTYPE html> <html lang="en"> &l ...