HDU 1260------简单DP
2015-07-16 21:45
288 查看
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:
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
Sample Output
Source
浙江工业大学第四届大学生程序设计竞赛
题意:
JOE是个卖票的人,他想要在最短的时间内把票卖完,他在上午八点开始卖票,求回到家的时间。
有N个样例,K表示有K个人,下面一行为每个人买票所需要的时间a,在下一行有K-1个数据,表示相邻两个人一起买票所需要的时间b。
dp[j]表示从第一个人到j人买票所花的最短时间,由题可得决策就两个过程,是选a还是选b。DP方程如下:
下面答案的输出有点繁琐,由于是am,pm表示,所以是12小时制。在24小时制的情况下0:00:00~12:59:59都是am,剩下的就是pm。代码如下:
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:
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
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:b int 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"); } }
相关文章推荐
- 调用有道词典查询单词
- 10763 Foreign Exchange 解题心得
- POJ 1700 坐船过河问题
- boost之any源码解析
- 折半查找
- Scala中的var val/def
- 以Java属性文件的格式创建Hibernate的配置文件和DTD特殊符号作用
- IDEA 扩大tomcat内存
- Xcode 模拟器复制解决方案
- win7下安装MySQL
- css属性:改变鼠标形状
- 一分耕耘一分收获,精诚所至金石为开
- Linux 设备驱动之 UIO 机制(二)
- 企业级电商一般包含哪些模块总结
- 背景音乐功能
- 计算机视觉相关会议
- 查看网络图片
- 函数的工作原理——划分RAM搞不懂啊???
- codeforces 558B. Amr and The Large Array 解题报告
- JAVA程序运行时 对象的放置安排及内存的分配