题目链接: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. AE的Annotation学习摘记

    http://xg-357.blog.163.com/blog/static/36263124201151763512894/ IFeatureWorkspaceAnno pFWSAnno = (IF ...

  2. Android网络通信之Socket

    在移动APP开发中.网络通信数据传输是必定存在的.移动APP离开了网络通信数据传输的功能方式,就好比一潭死水,永远都 是原来的样子. 提到网络通信传输数据.首先出如今程序猿脑海中的是HTTP协议传输, ...

  3. C# 性能优化 之 秒表 Stopwatch。 Dapper一个和petapoco差不多的轻量级ORM框架

    Sweet小马 小马同学的编程日记. C# 性能优化 之 秒表 Stopwatch. 生词解释:Diagnostics[,daɪəg'nɑstɪks] n.诊断学 using System.Diagn ...

  4. 使用python转换markdown to html

    起因 有很多编辑器可以直接将markdown转换成html,为什么还要自己写呢?因为我想写完markdown之后,即可以保存在笔记软件中(比如有道),又可以放到github进行版本管理,还可以发布到博 ...

  5. Linux文件系统与磁盘管理

    Linux文件系统与磁盘管理 有哪些文件系统: FAT:微软在Dos/Windows系列操作系统中共使用的一种文件系统的总称.       exFAT(Extended File Allocation ...

  6. VMware 虚拟机添加硬盘以及为新添加的硬盘创建Samba共享 (转)

    一.为VMware虚拟机添加硬盘 1. 首先在VMware虚拟机的VM->Setting子菜单中为虚拟机添加一块15G大小的SCSI类型的硬盘(注意:如果原来为IDE硬盘,SCSI类型的硬盘可能 ...

  7. 2016/04/26 权限 数据库mydb2 五个表 分别是 1,用户 2,角色 3,权限 4,用户对应的角色 5,角色对应的权限

    权限:   1,后台分配角色     角色对应权限    2,各用户通过登录页面登录    查看到各自的权限 五个页面   加引入一个jquery-1.11.2.min.js 1,guanli.php ...

  8. 初识 flask

    1,Python现阶段三大主流web框架Django, Tornado, Flask对比 Django主要特点是大而全,集成了很多组件,列如:Models Admin Form等等,不管用得用不着反正 ...

  9. Koa2学习(三)GET请求

    Koa2学习(三)GET请求 GET请求是前后端交互最常用的请求之一,常常用来进行查询操作. 那么Koa是如何接收并处理GET请求呢? 创建一个服务 // 引入Koa const Koa = requ ...

  10. bat文件中调用传参的问题

    https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-lin ...