HDUOJ 1260 Tickets

编程入门 行业动态 更新时间:2024-10-25 09:30:45

HDUOJ 1260 Tickets

题目链接

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.

Input

There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:

An integer K(1<=K<=2000) representing the total number of people;K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;(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~
用 d p [ i ] dp[i] dp[i] 表示第 i i i 个人所需的最短时间,则有状态转移方程:
d p [ i ] = m i n ( d p [ i − 1 ] + s [ i ] , d p [ i − 2 ] + d [ i ] ) , i ≥ 2 dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i]),i\geq2 dp[i]=min(dp[i−1]+s[i],dp[i−2]+d[i]),i≥2
注意输出格式,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n,s[2005],d[2005],dp[2005];
int main(){scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&s[i]);for(int i=1;i<=n-1;i++) scanf("%d",&d[i]);memset(dp,0,sizeof(dp));dp[1]=s[1];for(int i=2;i<=n;i++){dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i-1]);}int hour=dp[n]/3600,minute=(dp[n]/60)%60,second=dp[n]%60;if(hour<4) printf("%02d:%02d:%02d am\n",hour+8,minute,second);else printf("%02d:%02d:%02d pm\n",hour+8,minute,second);}
}

更多推荐

HDUOJ,Tickets

本文发布于:2023-05-24 16:42:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HDUOJ   Tickets

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!