Lemonade Trade
4990: Lemonade Trade
时间限制: 1 Sec 内存限制: 128 MB Special Judge
提交: 88 解决: 17
[提交][状态][讨论版][命题人:admin]
题目描述
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.
输入
• 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.
输出
样例输入
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的更多相关文章
- 2017 Benelux Algorithm Programming Contest (BAPC 17) Solution
A - Amsterdam Distance 题意:极坐标系,给出两个点,求最短距离 思路:只有两种方式,取min 第一种,先走到0点,再走到终点 第二种,走到同一半径,再走过去 #include ...
- gym101666题解
A Amsterdam Distance 题意 求圆环上的两点距离. 分析 显然是沿半径方向走到内圈再走圆弧最短. 代码 #include <bits/stdc++.h> using na ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)
题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...
- HDU 3401 Trade dp+单调队列优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...
- 【HDU 1009】FatMouse' Trade
题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- WPF后台修改内容界面不显示问题
通知3部曲:1.Model继承并实现 INotifyPropertyChanged 接口:2.数据集合使用ObservableCollection<T>集合:3.View使用Binding ...
- 数据库路由中间件MyCat - 源代码篇(9)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 3.5 后端连接 3.5.1 后端连接获取与负载均衡 上一节我们讲了后端连接的基本建立和响应 ...
- SCUT - 12 - 西方国家 - 矩阵快速幂
https://scut.online/p/12 可以用矩阵快速幂来做. #include<bits/stdc++.h> using namespace std; typedef long ...
- 洛谷P3797 妖梦斩木棒
P3797 妖梦斩木棒 题目背景 妖梦是住在白玉楼的半人半灵,拥有使用剑术程度的能力. 题目描述 有一天,妖梦正在练习剑术.地面上摆放了一支非常长的木棒,妖梦把它们切成了等长的n段.现在这个木棒可以看 ...
- codevs1245 最小的N个和
1245 最小的N个和 题目描述 Description 有两个长度为 N 的序列 A 和 B,在 A 和 B 中各任取一个数可以得到 N^2 个和,求这N^2 个和中最小的 N个.
- Mysql相关函数使用和总结(liet、right、substring、substring_index)
一.字段截取 1.从左开始截取字符串 用法:left(str,length),即:leift(被截取字符串,截取长度) 列子:select left(‘www.baidu.com’,8) 结果:www ...
- [WebShow系列] 倒计时展示相关问题
WebShow内置了倒计时功能. 后台参数维护: 倒计时参数说明: 倒计时基准时间设置(秒数):假设设置为90,也就是从1分30秒开始倒计时,同时有开始提示音. 倒计时提示1剩余秒数:假设设置为30, ...
- [LOJ 2022]「AHOI / HNOI2017」队长快跑
[LOJ 2022]「AHOI / HNOI2017」队长快跑 链接 链接 题解 不难看出,除了影响到起点和终点的射线以外,射线的角度没有意义,因为如果一定要从该射线的射出一侧过去,必然会撞到射线 因 ...
- HDU-3072-IntelligenceSystem(tarjan,贪心)
链接:https://vjudge.net/problem/HDU-3072 题意: 给你n个点,1个点到另一个点连接花费c,但是如果几个点可以相互可达,则这几个点连通花费为0. 求将整个图连通的最小 ...
- NET Core+MySql+Nginx
NET Core+MySql+Nginx 容器化部署 .NET Core容器化@Docker.NET Core容器化之多容器应用部署@Docker-Compose.NET Core+MySql+Ngi ...