HDU-1260_Tickets
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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:
- An integer K(1<=K<=2000) representing the total number of people;
- K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
- (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
题意:有t组输入,每组输入有三行,有n个人买票,第二行表示这n个人买票的时间,第三行表示这个人跟前一个人一起买票的时间。
题解:用dp[i]表示第几个人买票,转移方程dp[i] = min(dp[i-1]+这个人买票的时间,dp[i-2]+这个人跟前一个人一起买票的时间)
其中dp[1] = a[1]。
这道题的数据有点弱,下面两种输出都过了
if(h>=12)
{
h -= 12;
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
if(h>=12)
{
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t,n,i,dp[2050],a[2050],b[2050];
cin>>t;
while(t--)
{
cin>>n;
dp[0] = 0;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n-1;i++)
cin>>b[i];
dp[1] = a[1];
for(i=2;i<=n;i++)
dp[i] = min(dp[i-1] + a[i],dp[i-2] + b[i-1]);
int h,m,s;
h = dp[n] / 3600 + 8;
m = dp[n] / 60 % 60;
s = dp[n] % 60;
if(h>=24)
h %= 24;
if(h>=12)
{
h -= 12;
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
}
return 0;
}
HDU-1260_Tickets的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
- HDU 2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...
随机推荐
- placeholder IE兼容,显示password
从网上找了很多关于placeholder IE兼容性的问题,下边的这个js方法可以显示password. <!doctype html> <html lang="en&qu ...
- 在VUE中使用Echarts
第一步:下载echarts npm install echarts --save 第二步:在项目中main.js引入 import echarts from 'echarts' Vue.prototy ...
- java 7,8 排序异常
排序报 java.lang.IllegalArgumentException: Comparison method violates its general contract! 要明确返回-1, 0, ...
- Django 使用模板页面,块标签,模型
1.Django 使用模板页面 Django对于成体系的页面提出了模板继承和模板加载的方式. 1.导入静态页面 2.导入静态文件(css,js,images) 3.修改页面当中的静态地址 1.sett ...
- flask的基本操作
常用的SQLAlchemy字段类型 # coding:utf-8 from flask import Flask from flask_sqlalchemy import SQLAlchemy app ...
- 2019.9.29 csp-s模拟测试55 反思总结
不咕咕咕是一种美德[大雾] 头一次体会到爆肝写题解??? 这次考试我们没赶上,是后来掐着时间每个人自己考的.我最后的分数能拿到152…熟悉的一题AC两题爆炸. 强烈吐槽出题人起名走心 T1联: 发现每 ...
- SQL Sever实验二 交互式 SQL
一. 实验目的 1.观察查询结果, 体会 SELECT 语句实际应用: 2.要求学生能够使用 SELECT 语句进行数据库查询. 3. 熟练掌握各种查询的操作方法. 二. 实验准备 1. 完成实验一所 ...
- Vue.js @click点击无效?
原因, 那个点击的元素, 没有在 <div id="app"></div>里面
- Calendar to julian date format
1.JULIAN DATE 定义 2.示例: 定义枚举: public enum JulianDateType { /// <summary> /// J ...
- ip地址获取无效,自己修改ip地址
(1)