题目链接:
https://cn.vjudge.net/contest/68966#problem/H
AC代码;
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<map>
using namespace std;
# define maxn 2000+10
# define inf 0x3f3f3f3f
int one[maxn];
int two[maxn];
int dp[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d",&one[i]);
}
memset(two,inf,sizeof(two));
memset(dp,inf,sizeof(dp));
for(int i=2; i<=n; i++)
{
scanf("%d",&two[i]);
}
dp[0]=0;
for(int i=1; i<=n; i++)
{
if(i-2>=0)
dp[i]=min(dp[i-1]+one[i],min(dp[i-2]+two[i],dp[i]));
else if(i<=1&&i>=0)
dp[i]=min(dp[i-1]+one[i],dp[i]);
}//注意,这个是按照时间来进行的,
int t1=dp[n]/3600;
int t2=(dp[n]-t1*3600)/60;
int t3=dp[n]-t1*3600-t2*60;
if((t1+8)*3600+t2*60+t3<=12*3600)//注意,时间的起点是早上8点,并不是零点,然后如果是用am和pm表示的话,小时的单位一定是小等于12的。
{
t1+=8;
printf("%02d:%02d:%02d ",t1,t2,t3);
printf("am
");
}
else
{
t1+=8;
t1-=12;
printf("%02d:%02d:%02d ",t1,t2,t3);
printf("pm
");
}
}
return 0;
}