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 ...
随机推荐
- HDU - 6185 Covering(暴搜+递推+矩阵快速幂)
Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...
- 如何获取AppStore上应用的ipa安装包
1.首先你得去下载一个Apple Configurator 2,我们通过这个工具来获取ipa包,从AppStore上下载安装你需要获取的App 2.连接手机,打开Apple Configurator ...
- Git入门 时光穿梭鸡 版本回退 工作区 暂存区
分布式集中式 CVS及SVN都是集中式的版本控制系统 , 而Git是分布式版本控制系统 集中式版本控制系统,版本库是集中存放在中央服务器的, 而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得 ...
- gulp --watch直接退出,并没有监听
1.在es6(彩票项目)搭建环境时遇到gulp --watch 只运行一次就退出了不能监听: D:\nodejs\es6-base>gulp --watch [::] Failed to loa ...
- ue4 代码入门
官网:暴露游戏元素给蓝图 https://docs.unrealengine.com/latest/CHN/Engine/Blueprints/TechnicalGuide/ExtendingBlue ...
- 已知单链表的数据元素为整型数且递增有序,L为单链表的哨兵指针。编写算法将表中值大于X小于Y的所有结点的顺序逆置。(C语言)
对此题目的完整示例可直接运行代码如下: #include <stdio.h> #include <stdlib.h> typedef struct LNode{ int dat ...
- 第一个Three.js程序——动手写一个简单的场景
三维场景基本要素: 步骤: 代码: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- CC10:访问单个节点的删除
题目 实现一个算法,删除单向链表中间的某个结点,假定你只能访问该结点. 给定待删除的节点,请执行删除操作,若该节点为尾节点,返回false,否则返回true 解法 这道题并不难,主要是题目中这句话确定 ...
- Java中对象拷贝的两种方式
引用的拷贝 //引用拷贝 private static void copyReferenceObject(){ Person p = new Person(23, "zhang") ...
- 题解 UVA11354 【Bond】
并查集+按秩合并 传送门 大意:给出一张n个点m条边的无向图, 每条边有一个权值,有q个询问, 每次给出两个点s.t,找一条路, 使得路径上的边的最大权值最小. 我们可以发现,跑最小生成树会跑挂, 那 ...