hdu 1260 Tickets

本文介绍了一种通过优化购票流程来减少售票总时间的方法。针对多个购票者的情况,提出了允许相邻购票者组合购票以节省时间的策略,并给出了具体的实现算法及代码示例。

Tickets

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


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
 


这道题是说 有k个人买票。如果相邻的两个一起买票 就可以少花一些时间。求最短的卖票时间。

用s数组存储一个买票所需要花的时间。

用ss数组存储两个买票所花的时间。

那么状态转移方程就是opt[i]=min(opt[i-1]+s[i],opt[i-2]+ss[i-1]);

也就是说   第一种情况:.  第i人单独买+前i-1买票所需时间   第二种情况是 第i个人和第i-1人一起买+前i-2人买票所需要的最少时间。

 

只有多做 多刷 自己才能更明白更理解。

 

#include<iostream>
#include<iomanip>
using namespace std;
int ss[3000];
int s[3000];
int opt[3000];
int main()
{
 int cas,k,i,j,l,t,h,m,second;
 cin>>cas;
 while(cas--)
 {
 s[0]=0;
 cin>>k;
 for(i=1;i<=k;i++)
  cin>>s[i];
 ss[0]=0;
 for(j=1;j<=k-1;j++)
  cin>>ss[j];

 opt[0]=0;
 opt[1]=s[1];
 for(l=2;l<=k;l++)
 {
 opt[l]=opt[l-1]+s[l]<opt[l-2]+ss[l-1]?opt[l-1]+s[l]:opt[l-2]+ss[l-1];
 
 }
 
 t=opt[k];

 second=t%60;
 t=(t-second)/60;
 m=t%60;
 t=(t-m)/60;
 h=8+t;

 if(h<12)
 {
 cout<<setfill('0')<<setw(2)<<h<<':'<<setfill('0')<<setw(2)<<m<<':'<<setfill('0')<<setw(2)<<second<<" am"<<endl;

 }
 else
 {
 cout<<setfill('0')<<setw(2)<<h-12<<':'<<setfill('0')<<setw(2)<<m<<':'<<setfill('0')<<setw(2)<<second<<" pm"<<endl;
 
 }
 }


}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值