poj 3639(兑换美元)
来源:互联网 发布:网际网络转换器 编辑:程序博客网 时间:2024/04/29 05:07
题意:初始有加拿大的$1000,给出每天一个美国美元与加拿大美元的兑换率,每次兑换需要花费3%的手续费,并且还会把小于美分的给省去,问最后最多有多少加拿大美元。
题解:dp[i][0]为第i天最多有多少加拿大美元,dp[i][1]为第i天最多有多少美国美元,
dp[i][0]=max(dp[i-1][0],update(dp[i-1][1]*per*0.97));
dp[i][1]=max(update(dp[i-1][0]/per*0.97),dp[i-1][1]);
update是舍去美分以下的数。
#include<cstdio>#include<algorithm>#include<string>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>using namespace std; double dp[400][2]; double update(double x){ x*=100.0; int y=(int)x; return y/100.0; } int main(){ int n; while(scanf("%d",&n),n) { dp[0][0]=1000.0; dp[0][1]=0; for(int i=1;i<=n;i++) { double per; scanf("%lf",&per); dp[i][0]=max(dp[i-1][0],update(dp[i-1][1]*per*0.97)); dp[i][1]=max(update(dp[i-1][0]/per*0.97),dp[i-1][1]); } printf("%.2lf\n",dp[n][0]); } return 0; }
- poj 3639(兑换美元)
- POJ 1860 Currency Exchange 货币兑换★
- Poj 1860 Currency Exchange + Poj 2240 Arbitrage (货币兑换问题+最短路)
- poj 3181 Dollar Dayz 钱币兑换问题 大数/高精度 完全背包
- 积分兑换
- 积分兑换
- 积分兑换
- 兑换积分
- 积分兑换
- 积分兑换
- 兑换零钱
- 钱币兑换
- 硬币兑换
- 金币兑换
- 钱币兑换
- 货币兑换
- 硬币兑换
- 外币兑换
- gps纠偏技术的博客
- jquery.validationEngine ajax验证问题
- android 解析xml文件的三种方式
- AsyncChannel 的作用
- Linux 内核内存检测工具 - Kmemcheck
- poj 3639(兑换美元)
- C/C++编程GUI库比较
- win7打开方式选择默认程序导致应用程序无法打开
- hibernate4组件映射
- 深入浅出FFMPEG
- google gson 包下载地址
- C# system.data.sqlite使用
- 极光推送技术原理:移动无线网络长连接
- 链路层成帧方式