zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    mysql 查询每个分组前N条记录
    MLlib 卡方检验
    还好,我还在路上
    从浏览器渲染原理,浅谈回流重绘与性能优化
    基于vue-simple-uploader封装文件分片上传、秒传及断点续传的全局上传插件
    Vue2.0结合webuploader实现文件分片上传
    在Vue2.0中集成UEditor 富文本编辑器
    深入研究-webkit-overflow-scrolling:touch及ios滚动
    JS对象的截取和合并
    CSS变量--CSS和JavaScript的桥梁
  • 原文地址:https://www.cnblogs.com/iloveysm/p/12363864.html
Copyright © 2011-2022 走看看