zoukankan      html  css  js  c++  java
  • 【HDOJ】1903 Exchange Rates

    水DP。精度很坑。

     1 /* hdoj 1903 */
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cmath>
     6 
     7 #define MAXN 505
     8 
     9 double a[MAXN];
    10 double dp[MAXN][2];
    11 
    12 double max(double a, double b) {
    13     return a>b ? a:b;
    14 }
    15 
    16 inline double cal(double x, double f) {
    17     return floor(x*f*0.97*100.)/100.0;
    18 }
    19 
    20 int main() {
    21     int t, n;
    22     int i, j, k;
    23     double tmp;
    24     
    25     #ifndef ONLINE_JUDGE
    26         freopen("data.in", "r", stdin);
    27     #endif
    28     
    29     while (scanf("%d", &n)!=EOF && n) {
    30         for (i=1; i<=n; ++i)
    31             scanf("%lf", &a[i]);
    32         dp[0][0] = 0.0;
    33         dp[0][1] = 1000.0;
    34         for (i=1; i<=n; ++i) {
    35             dp[i][0] = max(dp[i-1][0], cal(dp[i-1][1], 1./a[i]));
    36             dp[i][1] = max(dp[i-1][1], cal(dp[i-1][0],    a[i]));
    37         }
    38         printf("%.2lf
    ", dp[n][1]);
    39     }
    40     
    41     return 0;
    42 }
  • 相关阅读:
    单(single)
    cdq分治
    寿司
    qtth
    二分,倍增的一些思考(lost my music:可持久化栈)
    手写堆、哈希表
    保留字,关键字
    测试19,20,21
    要买的书
    测试18:T2:可爱精灵宝贝
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4249563.html
Copyright © 2011-2022 走看看