描述

Now that the Loonie is hovering about par with the Greenback, you have decided to use your $1000 entrance scholarship to engage in currency speculation. So you gaze into a crystal ball which predicts the closing exchange rate between Canadian and U.S. dollars for each of the next several days. On any given day, you can switch all of your money from Canadian to U.S. dollars, or vice versa, at the prevailing exchange rate, less a 3% commission, less any fraction of a cent.
Assuming your crystal ball is correct, what's the maximum amount of money you can have, in Canadian dollars, when you're done?

输入

The input contains a number of test cases, followed by a line containing 0. Each test case begins with 0 <d ≤ 365, the number of days that your crystal ball can predict. d lines follow, giving the price of a U.S. dollar in Canadian dollars, as a real number.

输出

For each test case, output a line giving the maximum amount of money, in Canadian dollars and cents, that it is possible to have at the end of the last prediction, assuming you may exchange money on any subset of the predicted days, in order.

样例输入

3
1.0500
0.9300
0.9900
2
1.0500
1.1000
0

样例输出

1001.60
1000.00

思路

用两个数存储如果转换的美元和加币的金额。精度是个坑,这种小数点后两位的数据,可以先乘以100,最后结果输出的时候再除以100就可以了。

代码

#include<bits/stdc++.h>
using namespace std;double a[400];int main(){int n;while(cin>>n&&n){for(int i=0;i<n;i++) cin>>a[i];int k=100000,l=0;//l要设置成0 for(int i=0;i<n;i++){double kk=k,ll=l;k=max(k,int(ll*a[i]*0.97));//3%手续费 l=max(l,int(kk/a[i]*0.97));}printf("%.2f\n",k/100.0);}return 0;
}

2421:Exchange Rates——动态规划相关推荐

  1. D16:Exchange Rates(汇率,翻译)

    原题:OpenJudge - 2421:Exchange Rates 翻译: 描述:现在加元与美元不相上下,你已经决定要用你的1000美元的入学奖学金来从事货币投机(也就是换钱).所以你盯着一个能预测 ...

  2. 【noi 2.6_2421】Exchange Rates(DP)

    题意:起始有1000元美元,给出N天美元与加拿大元的汇率.问N天内可以不停的兑换,每次兑换需要收取3%的手续费,问可以得到的最大的美元数. 解法:直接用2个变量存第 i 天时手中是美元和加拿大元的最大 ...

  3. 百练 / 2016计算机学科夏令营上机考试: E

    题目来源:http://noi.openjudge.cn/ch0206/2421/ 2421:Exchange Rates 总时间限制: 1000ms      内存限制: 65536kB 描述 No ...

  4. ACM: 百练NOI——基本算法之动态规划

    文章目录 Maximum sum(求两个不重叠子区间最大和) Post Office(感觉题解有问题) 最长上升子序列 最大子矩阵 采药(0-1背包) 最长公共子序列 吃糖果 登山 最长公共上升子序列 ...

  5. Currency Exchange——最短路Bellman-Ford算法

    [题目描述] Several currency exchange points are working in our city. Let us suppose that each point spec ...

  6. *【POJ - 1860】Currency Exchange (单源最长路---Bellman_Ford算法判正环)

    题干: Description Several currency exchange points are working in our city. Let us suppose that each p ...

  7. Currency Exchange(判断有无正环)

    题目描述 Several currency exchange points are working in our city. Let us suppose that each point specia ...

  8. POJ 1860 Currency Exchange 最短路+负环

    原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  9. Currency Exchange (SPFA)

    点击打开链接 Problem Description Several currency exchange points are working in our city. Let us suppose ...

最新文章

  1. Java_Path_01_路径问题
  2. 字符串匹配的KMP算法和C语言代码,不需要思考就能理解
  3. ajax怎样获得表头信息,layui.table动态获取表头和列表数据示例
  4. 每日一皮:这个食堂好...
  5. CTFshow 命令执行 web46
  6. MyBatis 与 Hibernate
  7. AcWing算法基础课 Level-2 第二讲 数据结构
  8. math python 向上取整_Python成为专业人士笔记-各数学运算操作深度剖析
  9. nssstring 转换大小写
  10. 7-15 城市间紧急救援 (10 分)
  11. c语言malloc和直接声明,问下关于malloc的声明问题
  12. mysql子查询总分最高的学生_mysql高级内容
  13. PHP Web Shell in browser
  14. python矩阵运算_python 矩阵运算
  15. python 自动批量打开网页
  16. 地图标识符号大全_资源小结:分省地图查询(9.1版)
  17. 2021年法国经济发展研究报告
  18. LaTeX排版学习资源汇总
  19. 计算机病毒课后讨论题,《防治计算机病毒》答辩题目及解析
  20. BigSur下Safari14.1.1安装油猴插件(Tampermonkey)

热门文章

  1. 麒麟信安操作系统:挖掘场景,与云俱进 ——携手openEuler赋能关键行业应用
  2. esxi下搭建软路由
  3. IE 浏览器 判断 增加 支持 IE8 IE9 IE10 IE11等 IE浏览器(是不是IE浏览器判断)
  4. php 公众号发表文章,微信公众号如何发布文章最基本教程
  5. 马云:不要买房了,未来房子如葱!10年后最便宜的是房子车子,而最贵的是…...
  6. 浅学 ------ 爬虫(一)
  7. Tomb.finance每周更新(11.8-14)
  8. 紧耦合LIO综述 | 6篇顶会论文看透紧耦合LIO玩儿法(LIOM/LIO-SAM)
  9. 基音周期计算(pitch tracking)
  10. 速度/效率远比你以为的重要