题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260

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

解题思路:这是一道简单的DP,题目的意思就是有两种购票方式,要么采用单独购票,要么采用双人购票,求N个人购完票所花费的最小时间。简单推导易得状态转移方程:dp[i] = min(dp[i-1]+tim[i],dp[i-2]+together[i]);两种情况:①前面i-1个人所消耗的时间加上当前单人购票时间;②前i-2个人购票时间加上当前双人购票时间;取这两种情况的最小值即为最小花费时间。之后还要对时间显示格式进行处理,这里应该是12小时制,即超过12小时显示为pm且取余12。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int tim[],together[],dp[];
int main(){
int N,K;
cin>>N;
while(N--){//表示N种情况
cin>>K;//表示总人数
for(int i=;i<=K;i++)cin>>tim[i];//读入单个人购票消耗时间
for(int i=;i<=K;i++)cin>>together[i];//读入连续两人购票所消耗的时间
dp[]=,dp[]=tim[];//初始两个人的购票时间为dp[0]=0,第一个人单人购票所花费的时间dp[1]=tim[1]
for(int i=;i<=K;i++)//从第二个人购票开始计算时间
dp[i]=min(dp[i-]+tim[i],dp[i-]+together[i]);
int sec=dp[K]%;//保存秒
int minu=(dp[K]/)%;//保存分钟
int hour=dp[K]/+;//保存小时
int flag=;//标记是否超过12点
if(hour>){flag=;hour%=;}
printf("%02d:%02d:%02d ",hour,minu,sec);
if(flag)cout<<"pm"<<endl;
else cout<<"am"<<endl;
}
return ;
}

题解报告:hdu 1260 Tickets的更多相关文章

  1. 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets

    2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...

  2. HDU 1260 Tickets (普通dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others)   ...

  3. HDU 1260 Tickets(简单dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  4. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...

  5. HDU - 1260 Tickets 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...

  6. HDU 1260 Tickets DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...

  7. HDU 1260 Tickets (动规)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  8. HDU 1260 Tickets (动态规划)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  9. HDU 1260 Tickets(基础dp)

    一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...

随机推荐

  1. django 简易博客开发 3 静态文件、from 应用与自定义

    首先还是贴一下源代码地址  https://github.com/goodspeedcheng/sblog 上一篇博客我们介绍了 django 如何在views中使用templates以及一些常用的数 ...

  2. Openwrt挂载NTFS硬盘提示“只读”错误的解决方法!

    Openwrt是基于Linux代码编写,只支持NTFS格式硬盘的只读权限,否则当挂载的NTFS硬盘写入超过2M左右,就会出现"error:read-only file system" ...

  3. vim配置为IDE环境(超详细,极力推荐 git)

    https://github.com/yangyangwithgnu/use_vim_as_ide 1. 用法 git clone https://github.com/VundleVim/Vundl ...

  4. 容器使用笔记(List篇)

    上一篇博客介绍了Dictionary,这篇博客介绍List的相关内容. C#中要存储一组数据.我们会想到数组Array,ArrayList,List这三个对象,当中,数组是最早出现的,我们就从数组開始 ...

  5. D广搜

    <span style="color:#330099;">/* D - 广搜 基础 Time Limit:1000MS Memory Limit:30000KB 64b ...

  6. java 配置时遇到的问题及解决办法

    1. 最近JDK更新很频繁,以至于我安装时版本太多,选择也会出现问题 首先,确定你选择的是32位版本还是64位版本(貌似64位系统下也可以安装32位的JDK), 这个相当重要,因为这个会影响到ecli ...

  7. hive计算网页停留时长

    hive表结构例如以下: create table pv_user_info( session_id string, user_id string, url string, starttime big ...

  8. 在Oracle数据库中使用NFS,怎样调优?

    MOS上有好多文章,基本上都跑不了以下三点: Setup can make a big difference 1. Network topology and load 2. NFS mount opt ...

  9. 2016/3/26 weixin 头像 昵称 网页优化显示 缺表中数据 只有代码 无显示效果

    weixin.php <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  10. JSON with Java

    work with json-lib.jar import net.sf.json.JSONArray;import net.sf.json.JSONException;import net.sf.j ...