http://acm.hdu.edu.cn/showproblem.php?pid=1260
Tickets
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.
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.
2 2 20 25 40 1 8
08:00:40 am 08:00:08 am
题意:每个人都有一个买票时间,并且又给出相邻两个人的买票时间,求最少多长时间能买完票。
思路:用dp[i]存前i个人的最小花费时间。
AC代码:
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define LL long long
#define eps 1e-8
using namespace std;
const int mod = 1e7+7;
const int INF = 1e8;
const int inf = 0x3f3f3f3f;
const int maxx = 100100;
const int N = 2050;
int a[N];
int b[N];
int dp[N];
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",&b[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]+b[i]);
int shi=8,fen=0,miao=0;
string c="am";
miao=dp[n];
fen+=miao/60;
miao%=60;
shi+=fen/60;
fen%=60;
if(shi>12)
{
shi-=12;
c="pm";
}
printf("%02d:%02d:%02d ",shi,fen,miao);
cout<<c<<endl;
}
}
322




被折叠的 条评论
为什么被折叠?



