InputThere are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
OutputFor every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input
2 2 20 25 40 1 8
Sample Output
08:00:40 am 08:00:08 am
#include<iostream> #include<cstring> #include<algorithm> #include<bits/stdc++.h> using namespace std; const int maxn=2010; int s[maxn],d[maxn]; int dp[maxn]; int main() { int t; cin>>t; while(t--) { int n; 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]; } dp[1]=s[1]; for(int i=2;i<=n;++i) { dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i]); } int time=(8+dp[n]/3600)%24; int m=(dp[n]/60)%60; int s=dp[n]%60; if(time>12) printf("%02d:%02d:%02d pm\n",time,m,s); else printf("%02d:%02d:%02d am\n",time,m,s); } return 0; }
原文:https://www.cnblogs.com/1shengxiao1/p/11226261.html