zoukankan      html  css  js  c++  java
  • HDU 1260 Tickets DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1260

    用dp[i]表示处理到第i个的时候用时最短。

    那么每一个新的i,有两个选择,第一个就是自己不和前面的组队,第二就是和前面的组队。

    那么dp[i] = min(dp[i - 1] + a[i], dp[i - 2] + b[i]);  前者是自己组队。

    边界条件 dp[0] = 0; dp[1] = a[1];

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    
    const int maxn = 2000 + 20;
    int a[maxn];
    int b[maxn];
    int dp[maxn];
    void work() {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &a[i]);
        }
        for (int i = 2; i <= n; ++i) {
            scanf("%d", &b[i]);
        }
        dp[0] = 0;
        dp[1] = a[1];
        for (int i = 2; i <= n; ++i) {
            dp[i] = min(dp[i - 1] + a[i], dp[i - 2] + b[i]);
        }
    //    cout << dp[n] << endl;
        int addHour = dp[n] / 60 / 60;
        int addMin = (dp[n] / 60) % 60;
        int addSec = dp[n] % 60;
        printf("%02d:%02d:%02d ", 8 + addHour, addMin, addSec);
        if (8 + addHour > 12) {
            printf("pm
    ");
        } else if (8 + addHour == 12) {
            if (addMin || addSec) {
                printf("am
    ");
            } else printf("pm
    ");
        }  else printf("am
    ");
        return;
    }
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        int t;
        scanf("%d", &t);
        while (t--) work();
        return 0;
    }
    View Code
  • 相关阅读:
    【Postgresql】set up
    【LSTM】Understanding-LSTMs
    【CTR】各公司方法
    【DL】stanford--cs20si--tensorflow
    Redis数据库入门教程
    用.htaccess文件实现URL重写
    php中urldecode()和urlencode()
    php中序列化与反序列化
    网站整合Ucenter详细流程
    ucenter 整合外部网站,实现登录等操作
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6003948.html
Copyright © 2011-2022 走看看