题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260
题目大意:
知道一个人买票花的时间和和前面那个人一起买票花的时间,问最少花多少时间可以把票卖完..
输入:
给出T,表示有T组样例
给出n,表示有n个人买票..
给出n个数表示这个人单独买票会花的时间..
给出n-1个数,表示这个人和前面那个人一起买票会花的时间..
Problem Description
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
Input
There 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.
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.
Output
For 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
思路:DP[i]代表以i结束的最小时间,则dp[i]=min(dp[i-1]+一个人买的时间,dp[i-2]+两个人买的时间),因为最大值都不会超过am,所以不用判上下午
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOU(i,x,y) for(int i=x;i<=y;i++)
#define FOD(i,x,y) for(int i=x;i>=y;i--)
#define MEM(a,val) memset(a,val,sizeof(a))
#define PI acos(-1.0)
const double EXP = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll MINF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const int N = 1e6+5;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
std::ios::sync_with_stdio(false);
int t,n;
int a[2005],b[2005];
int dp[2005]; //dp[i]代表以i结尾的最小时间
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i]=INF;
}
for(int i=2;i<=n;i++)
scanf("%d",&b[i]);
dp[0]=0;
dp[1]=a[1];
for(int i=2;i<=n;i++)
{
dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);
}
int ans=dp[n];
int h=8;
int m=0;
int s=0;
h+=ans/3600;
ans-=(ans/3600)*3600;
m+=ans/60;
ans-=(ans/60)*60;
s+=ans;
printf("%02d:%02d:%02d am\n",h,m,s);
}
return 0;
}