【dp每日一题】HDU 1260 Tickets
作者:互联网
HDU 1260 Tickets
大意:
给出n个人买票的时间以及他们每个人和下一个人合买双人票的时间,问最早什么时候能卖完票
思路:
\(dp[i]\)代表前i个人买完票需要多久,那么可以从\(dp[i-2]\)转移过来,也可以从\(dp[i-1]\)转移过来
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 5;
typedef long long LL;
int t, n, a[N], b[N], dp[N];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
dp[i] = 0x3f3f3f3f;
}
for (int i = 0; i < n - 1; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (i == 0) dp[i] = a[0];
else if (i == 1) dp[i] = min(a[0] + a[1], b[0]);
else dp[i] = min(dp[i - 2] + b[i - 1], dp[i - 1] + a[i]);
}
int res = dp[n-1];
int ss = res % 60;
int mm = (res / 60) % 60;
int hh = ((res / 60) / 60) % 60;
if (hh + 8 > 12) printf("%02d:%02d:%02d pm\n", hh - 4, mm, ss);
else printf("%02d:%02d:%02d am\n", hh + 8, mm, ss);
}
return 0;
}
标签:Tickets,02d,HDU,int,res,1260,60,hh,dp 来源: https://www.cnblogs.com/dyhaohaoxuexi/p/14190678.html