hdu1260Tickets(动态规划)

你的名字 2022-07-28 09:53 288阅读 0赞

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

  1. 2
  2. 2
  3. 20 25
  4. 40
  5. 1
  6. 8

Sample Output

  1. 08:00:40 am
  2. 08:00:08 am

Source

浙江工业大学第四届大学生程序设计竞赛

#include
#include
#include
#include
using namespace std;
#include
int dp[100000],one[100000],two[10000];
int main()
{
int n,T,i;
int a,b,c;
scanf(“%d”,&T);
while(T—)
{
scanf(“%d”,&n);
if(n>=2)
{
for(i=1;i<=n;i++)
scanf(“%d”,&one[i]);
for(i=2;i<=n;i++)
scanf(“%d”,&two[i]);
memset(dp,0,sizeof(dp));
dp[1]=one[1];
for(i=2;i<=n;i++)
{
dp[i]=min(dp[i-1]+one[i],dp[i-2]+two[i]);
}
//printf(“%d\n”,dp[n]);
c=dp[n];
b=c/60;
c=c-b*60;
a=b/60;
b=b-a*60;
a=a+8;
if(a>12)
printf(“%02d:%02d:%02d pm\n”,a-12,b,c);
else
printf(“%02d:%02d:%02d am\n”,a,b,c);
}
else
{
scanf(“%d”,&c);
b=c/60;
c=c-b*60;
a=b/60;
b=b-a*60;
a=a+8;
if(a>12)
printf(“%02d:%02d:%02d pm\n”,a-12,b,c);
else
printf(“%02d:%02d:%02d am\n”,a,b,c);
// printf()
}
}
return 0;
}

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

  1. 2
  2. 2
  3. 20 25
  4. 40
  5. 1
  6. 8

Sample Output

  1. 08:00:40 am
  2. 08:00:08 am

Source

浙江工业大学第四届大学生程序设计竞赛

发表评论

表情:
评论列表 (有 0 条评论,288人围观)

还没有评论,来说两句吧...

相关阅读

    相关 HDU 1978(动态规划)

    问题描述 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m)。游戏的规则描述如下:  1.机器人一开始在棋盘的起始点并有起始点所