HDOJ-1260(动态规划水题)

Tickets

HDOJ-1260

#include<bits/stdc++.h>
using namespace std;
const int maxn=2003;
int n;
int s[maxn];//single
int d[maxn];//double
int dp[maxn];//dp[i]表示前i个人买好票花费的最小费用
int main(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            cin>>s[i];
        }
        for(int i=2;i<=n;i++){
            cin>>d[i];
        }
        d[1]=s[1];
        dp[1]=s[1];
        for(int i=2;i<=n;i++){
            dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i]);
        }
        //cout<<dp[n]<<endl;
        int seconds=dp[n];
        int hours=seconds/3600;
        int minutes=(seconds%3600)/60;
        seconds=seconds-hours*3600-minutes*60;
        if(hours>=4){
            printf("%02d:%02d:%02d pm\n",8+hours,minutes,seconds);
        }else{
            printf("%02d:%02d:%02d am\n",8+hours,minutes,seconds);
        }
    }
    //system("pause");
    return 0;
}
posted @ 2019-10-08 09:15  Garrett_Wale  阅读(108)  评论(0编辑  收藏  举报