• hduTickes("简单"的dp)


    想退役了~

    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,一开始想的十分的复杂,想了三种转移状态还有端点处的特判,后来才发现其实只有两种.
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int n,m;
    int time[2005],total1[1000];
    int a[2005],b[2005];
    int fen,miao,shi,total;
    int s[2],f[2],mi[2];
    int main()
    {
        cin>>n;
        while(n--)
        {
            cin>>m;
            if(m!=1)
            {
                for(int i=1; i<=m; i++)
                    cin>>a[i];
                for(int i=2; i<=m; i++)
                {
                    cin>>time[i];
                }
                total1[0]=0;
                total1[1]=a[1];
                for(int i=2;i<=m;i++)
                {
                    total1[i]=min(total1[i-1]+a[i],total1[i-2]+time[i]);
                }
                total=total1[m];
            }
            if(m==1)
            {
                cin>>a[m];
                total+=a[m];
            }
            miao=total%60;
            fen=(total-miao)/60;
            shi=fen/60;
            fen=fen%60;
            shi+=8;
            f[0]=fen/10;
            f[1]=fen%10;
            s[0]=shi/10;
            s[1]=shi%10;
            mi[0]=miao/10;
            mi[1]=miao%10;
            if(shi<12)
                cout<<s[0]<<s[1]<<':'<<f[0]<<f[1]<<':'<<mi[0]<<mi[1]<<' '<<"am"<<endl;
            else
                cout<<s[0]<<s[1]<<':'<<f[0]<<f[1]<<':'<<mi[0]<<mi[1]<<' '<<"pm"<<endl;
            total=0;
            shi=0;
            miao=0;
            fen=0;
        }
        return 0;
    }
  • 相关阅读:
    php中 include 、include_once、require、require_once4个语言结构的含义和区别
    PHP yield 分析,以及协程的实现,超详细版(上)
    wordpress里的bloginfo()与get_bloginfo()
    CSS定位中“父相子绝”
    Apache 的 httpd.conf 详解
    apache的<directory>语句以及属性的含义
    你必须了解的Session的本质(PHP)
    Linux常用命令
    vmware中配置CentOS
    程序员可能会遇到的一些名词
  • 原文地址:https://www.cnblogs.com/iloveysm/p/12363864.html
Copyright © 2020-2023  润新知