标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1260
刚开始以为一个人只能和其相邻的其中一个来实现贪心
其实一个人(如果前后都有人)可以多次结合用来贪心
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3141 Accepted Submission(s): 1540
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include<vector> #include<algorithm> using namespace std; #define PI 3.1415926 const int maxn=10007; const int INF=0x3f3f3f3f; int dp[maxn], a[maxn], c[maxn]; int main() { int T; scanf("%d", &T); while(T--) { 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", &c[i]); memset(dp, 0, sizeof(dp)); dp[1]=a[1]; ///刚开始以为一个人只能和其相邻的其中一个来实现贪心 ///其实一个人(如果前后都有人)可以多次结合用来贪心 for(int i=2; i<=n; i++) dp[i]=min(dp[i-1]+a[i], dp[i-2]+c[i]); int hh=dp[n]/3600; int mm=(dp[n]%3600)/60; int ss=dp[n]%60; printf("%02d:%02d:%02d%s\n", (hh+8)%24, mm, ss, (hh+8)%24>12?" pm":" am"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/w-y-1/p/5748437.html