HDU 1260------简单DP
来源:互联网 发布:小型公司网络搭建案例 编辑:程序博客网 时间:2024/06/05 02:00
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
2220 254018
Sample Output
08:00:40 am08:00:08 am
Source
浙江工业大学第四届大学生程序设计竞赛
题意:
JOE是个卖票的人,他想要在最短的时间内把票卖完,他在上午八点开始卖票,求回到家的时间。
有N个样例,K表示有K个人,下面一行为每个人买票所需要的时间a,在下一行有K-1个数据,表示相邻两个人一起买票所需要的时间b。
dp[j]表示从第一个人到j人买票所花的最短时间,由题可得决策就两个过程,是选a还是选b。DP方程如下:
dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i-1]);下面答案的输出有点繁琐,由于是am,pm表示,所以是12小时制。在24小时制的情况下0:00:00~12:59:59都是am,剩下的就是pm。代码如下:
#include<stdio.h>#include<string.h>#define min(a,b) a<b?a:bint dp[2001];int main(){int n,sum,h,m,s,t,k;scanf("%d",&n);while(n--){scanf("%d",&k);int a[2001],b[2001];for(int i=1;i<=k;i++){scanf("%d",&a[i]);}dp[1]=a[1];dp[0]=0;for(int i=1;i<k;i++) scanf("%d",&b[i]); for(int i=2;i<=k;i++) dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i-1]);sum=dp[k];h=sum/3600;sum=sum%3600;m=sum/60;s=sum%60;h=(h+8)%24;t=h/13;h=h%12;if(h>=10) printf("%d:",h); else printf("0%d:",h); if(m>=10) printf("%d:",m); else printf("0%d:",m); if(s>=10) printf("%d ",s); else printf("0%d ",s); if(t) printf("pm\n"); else printf("am\n");}}
0 0
- HDU 1260------简单DP
- HDU 1260 Tickets (简单DP)
- HDU 1260 Tickets 简单DP
- hdu Tickets 1260 (简单DP)
- HDU 1260 Tickets 简单dp
- HDU 1260 Tickets(简单DP)
- 【HDU】-1260-Tickets(简单DP)
- HDU 1087 简单DP
- hdu 1978 简单dp
- hdu 2830 简单dp
- hdu 2151 简单dp
- hdu 3199 简单dp
- HDU DP 简单题
- hdu 4540(简单dp)
- hdu 2152(简单dp)
- HDU 4502 简单DP
- hdu 1087 简单dp
- HDU 1003(简单dp)
- Scala中的var val/def
- IDEA 扩大tomcat内存
- 【模拟】zoj3359
- Binary Tree Traversal (二)
- [leetcode-210]course scheduleII(java)
- HDU 1260------简单DP
- php和js中数组中分别循环找出最大的数。
- HDU 1398 Square Coins
- 2014华为机试(一)
- android混淆打包配置(忽略第三方jar)
- 开启新的学习模式
- UVA 11877 The Coco-Cola Store
- 字符集和字符编码Q&A
- android 学习笔记之 post get 方式与 服务器JSON通信