Tickets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3780    Accepted Submission(s): 1896

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
2
2
20 25
40
1
8
 
Sample Output
08:00:40 am
08:00:08 am
 
Source
 

题意:

处理k件事依次排列,每有一个件事单独处理时间,又知道相邻的两件事同时处理的时间,问这k件事最少的处理时间

代码:

//每件事考虑单独处理和他与前一个同时处理两种情况,dp求最小即可。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int f[][],n,k,a[],b[];
int main()
{
scanf("%d",&n);
while(n--){
scanf("%d",&k);
for(int i=;i<=k;i++) scanf("%d",&a[i]);
for(int i=;i<=k;i++) scanf("%d",&b[i]);
f[][]=a[];f[][]=a[];
for(int i=;i<=k;i++){
f[][i]=min(f[][i-]+a[i],f[][i-]+a[i]);
f[][i]=f[][i-]-a[i-]+b[i];
}
int sum=min(f[][k],f[][k]);
int se=sum%;
int mi=(sum/)%;
int ho=((sum/)/)%+;
int x1,x2,x3,x4,x5,x6,flag=;
if(ho>) {ho-=;flag=;};
x1=ho/;x2=ho%;x3=mi/;x4=mi%;x5=se/;x6=se%;
printf("%d%d:%d%d:%d%d ",x1,x2,x3,x4,x5,x6);
if(flag) printf("pm\n");
else printf("am\n");
}
return ;
}

HDU1260DP的更多相关文章

随机推荐

  1. kubernetes相关

    1.获取client , api-server 加token 或in-cluster方式 2.所有对象均有list update get 等方法 3.对象属性源码追踪,yaml与源码一一对应 4.一些 ...

  2. mac os x下应用endnote异常解决办法

    最近在用Office+Endnote写论文,使用拼音输入法换字时会出现重字和拼音的情况,比如我想打“桥连”,最终出现的是"qiao'lian桥lian桥连”.后来发现这个问题时由endnot ...

  3. Windows下PATH等环境变量详解(转载)

    本文转载自http://legend2011.blog.51cto.com/3018495/553255 在学习JAVA的过程中,涉及到多个环境变量(environment variable)的概念, ...

  4. POJ 1639 Picnic Planning(最小度限制生成树)

    Description The Contortion Brothers are a famous set of circus clowns, known worldwide for their inc ...

  5. Block的声明与定义语法

    Block的声明 Block的声明与函数指针的声明类似 返回值类型(^变量名)(参数列表) Block的定义 ^返回值类型(参数列表) { 表达式 } 其中: 1 如果返回值类型是void,可以省略 ...

  6. LintCode-38.搜索二维矩阵 II

    搜索二维矩阵 II 写出一个高效的算法来搜索m×n矩阵中的值,返回这个值出现的次数. 这个矩阵具有以下特性: 每行中的整数从左到右是排序的. 每一列的整数从上到下是排序的. 在每一行或每一列中没有重复 ...

  7. HDU 2163 Palindromes

    http://acm.hdu.edu.cn/showproblem.php?pid=2163 Problem Description Write a program to determine whet ...

  8. 【Linux】- Ubuntu 配置mysql远程访问

    ubuntu上安装mysql非常简单只需要几条命令就可以完成. sudo apt-get install mysql-server   安装过程中会提示设置密码什么的,注意设置了不要忘了,安装完成之后 ...

  9. JAVA学习之泛型

    ArrayList<E>类定义和ArrayList<Integer>类引用中涉及的术语:1.整个ArrayList<E>称为泛型类型 2.ArrayList< ...

  10. BZOJ4736 温暖会指引我们前行(LCT+最大生成树)

    类似于瓶颈路,满足条件的路径一定在温度的最大生成树上,那么就是一个LCT维护MST的裸题了. #include<iostream> #include<cstdio> #incl ...