hdu 1260 Tickets
2013-08-07 11:38
288 查看
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 751 Accepted Submission(s): 379
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
2
20 25
40
1
8
[align=left]Sample Output[/align]
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;
}
}
}
相关文章推荐
- hdu 1260 Tickets (dp)
- HDU 1260 Tickets (简单DP)
- [ACM] hdu 1260 Tickets (动态规划)
- HDU 1260 Tickets 【dp】
- hdu 1260 Tickets(DP)
- DP-HDU-1260-Tickets
- HDU 1260 Tickets(简单dp)
- HDU 1260 Tickets 找状态方程
- HDU 1260 Tickets
- HDU 1260 Tickets(简单DP)
- [HDU 1260] Tickets
- HDU-1260 Tickets(DP)
- HDU 1260 Tickets(DP OR 记忆化搜索)
- hdu 1260 Tickets(DP)
- 【HDU】-1260-Tickets(简单DP)
- HDU 1260 Tickets
- hdu 1260 Tickets(dp)
- hdu 1260——Tickets
- hdu 1260 Tickets(DP)
- hdu 1260 (Tickets)