Tickets
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1260/
首先是要理解题目的意思。
大概是这样:乔卖电影票,可以单张卖,也可以两张连在一起卖,求最短时间。
首先输入N,代表N种场景数,然后输入K,代表观众数,接下来先输入K个数,分别代表K个观众单独买票所需时间,然后输入K-1个数,分别代表K-1对连续的观众买票所需时间。每个人可以选择自己买票,也可以选择跟相邻的人一起买票。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, k, each[2001], both[2001], result[2001];
cin >> n;
while (n--)
{
cin >> k;
for (int i = 1; i <= k; i++)
cin >> each[i];
for (int i = 1; i <= k - 1; i++)
cin >> both[i];
result[0] = 0;
result[1] = each[1];
for (int i = 2; i <= k; i++)
{
result[i] = min(each[i] + result[i - 1], both[i - 1] + result[i - 2]);
}
int time = result[k];
int h, m, s, t;
h = time / 3600 + 8;
time = time % 3600;
m = time / 60;
s = time % 60;
if (h <= 12)
t = 0;
else
{
t = 1;
h -= 12;
}
if (h < 10)
cout << 0;
cout << h << ':';
if (m < 10)
cout << 0;
cout << m << ':';
if (s < 10)
cout << 0;
cout << s;
if (t == 0)
cout << " am" << endl;
else
cout << " pm" << endl;
}
return 0;
}