hdoj 1260(简单dp)

Tickets

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

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,但是想了好久想不出。。。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int maxn=2006;
 6 int one[maxn],two[maxn];
 7 int dp[maxn];
 8 int out[4];
 9
10 int my_min(int a,int b)
11 {
12     return a<b?a:b;
13 }
14
15 void output(int ti)
16 {
17     if(ti==0){
18         if(out[3]>=12) cout << " pm" << endl;
19         else cout << " am"<<endl;
20         return ;
21     }
22     if(ti==3){
23         if(out[ti]<10) cout << "0" << out[ti];
24         else cout << out[ti];
25     }
26     else{
27         if(out[ti]<10) cout << ":0"<< out[ti];
28         else cout<< ":" << out[ti];
29     }
30     output(ti-1);
31 }
32
33 int main()
34 {
35     ios_base::sync_with_stdio(0); cin.tie(0);
36     int T;
37     cin >> T;
38     while(T--){
39         int k;
40         memset( dp, 0, sizeof dp);
41         cin >> k;
42         for(int i=1;i<=k;i++)
43             cin >> one[i];
44         for(int i=2;i<=k;i++)
45             cin >> two[i];
46         dp[1]=one[1];
47         for(int i=2;i<=k;i++){
48             dp[i]=my_min( dp[i-1]+one[i], dp[i-2]+two[i]);
49         }
50
51         out[1]=dp[k];
52         out[3]=8;
53         out[2]=out[1]/60;
54         out[1]=out[1]%60;
55         out[3]=out[3]+out[2]/60;
56         out[2]=out[2]%60;
57         output(3);
58     }
59     return 0;
60 }

我的超水输出。

看看大神的输出。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int maxn=2006;
 6 int one[maxn],two[maxn],dp[maxn];
 7
 8 int my_min(int a,int b)
 9 {
10     return a<b?a:b;
11 }
12
13 int main()
14 {
15     int T;
16     cin >> T;
17     while(T--){
18         int k;
19         memset( dp, 0, sizeof dp);
20         cin >> k;
21         for(int i=1;i<=k;i++)
22             cin >> one[i];
23         for(int i=2;i<=k;i++)
24             cin >> two[i];
25         dp[1]=one[1];
26         for(int i=2;i<=k;i++){
27             dp[i]=my_min( dp[i-1]+one[i], dp[i-2]+two[i]);
28         }
29         int temp,ss,hh,mm;
30         temp=dp[k];
31         char s[5];
32         ss=temp%60;
33         mm=(temp-ss)/60%60;
34         hh=(temp-ss-mm*60)/3600+8;
35         if(hh>=12)
36             strcpy( s, "pm");
37         else strcpy( s, "am");
38         printf("%02d:%02d:%02d %s\n",hh,mm,ss,s);
39     }
40     return 0;
41 }

原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9089748.html

时间: 2024-11-05 14:37:45

hdoj 1260(简单dp)的相关文章

Tickets HDU - 1260 简单dp

#include<iostream> using namespace std; const int N=1e5; int T,n; int a[N],b[N]; int dp[N]; int main() { cin>>T; while(T--) { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n-1;i++) cin>>b[i]; dp[1]=a[1]; for(i

POJ 3250 Bad Hair Day 简单DP 好题

Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

hdu1207 汉诺塔II 简单dp

本文出自:http://blog.csdn.net/svitter 题意:汉诺塔,多了一根柱子,问你寻找最快的移动次数. dp [ n ] = dp [ n - j ] * 2 + pow( 2, j ) - 1; 就是把j个汉诺塔移到一根上dp[ n - j ],然后就是普通的汉诺塔问题,即2^n - 1次移动, 然后把剩下的移动过去dp [ n - j ]. 注意pow(2, j )可能超出long long int范围.写二的次方的时候也可用移位算法. #include <iostream

POJ1088:滑雪(简单dp)

题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一下序,因为只能高度递减才能滑行.之后就很简单了,就是简单DP. 即:要求的滑坡是一条节点递减并依次相邻的最长路径,可以先根据高度将所有的点进行排序,在i点的时候,遍历0~i-1个点(升序排序,i前面的点的高度一定小于等于i),取相邻点间的大的路径长度 代码如下: #include <iostream

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

hdu1087 简单DP

I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HD

2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题

听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到100即可 算最大GPA的时候,首先每个科目分配到60分,然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到85即可,如果还有REMAIN POINT,就FOR循环下来加到100上限即可 不会DP 阿 QAQ 过段时间得好好看DP了  =  = 于是默默的把这题标记为<水题集> //

Codeforces 41D Pawn 简单dp

题目链接:点击打开链接 给定n*m 的矩阵 常数k 下面一个n*m的矩阵,每个位置由 0-9的一个整数表示 问: 从最后一行开始向上走到第一行使得路径上的和 % (k+1) == 0 每个格子只能向或走一步 求:最大的路径和 最后一行的哪个位置作为起点 从下到上的路径 思路: 简单dp #include <cstdio> #include <algorithm> #include<iostream> #include<string.h> #include &

HDU 4826 简单DP

Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向上向下向右走以前没有走过的格子,每一个格子中都有一些金币(或正或负,有可能遇到强盗拦路抢劫,度度熊身上金币可以为负,需要给强盗写欠条),度度熊刚开始时身上金币数为0,问度度熊走出迷宫时候身上最多有多少金币? Input 输入的第一行是一个整数T(T < 200),表示共有T组数据.每组数据的

UVA - 11584 划分字符串的回文串子串; 简单dp

/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单dp 题目大意: 给一个字符串, 要求把它分割成若干个子串,使得每个子串都是回文串.问最少可以分割成多少个. 定义:dp[i]表示前0~i内的字符串划分成的最小回文串个数: dp[i] = min(dp[j]+1 | j+1~i是回文串); 先预处理flag[i][j]表示以i~j内的字符串为回文串