博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 2419: Ferry Loading II
阅读量:6314 次
发布时间:2019-06-22

本文共 2095 字,大约阅读时间需要 6 分钟。

2419: Ferry Loading II 分享至QQ空间

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
Total Submit: 4            Accepted:3

Description

Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry. 

There is a ferry across the river that can take n cars across the river in t minutes and return in t minutes. m cars arrive at the ferry terminal by a given schedule. What is the earliest time that all the cars can be transported across the river? What is the minimum number of trips that the operator must make to deliver all cars by that time?

Input

The first line of input contains c, the number of test cases. Each test case begins with n, t, m. m lines follow, each giving the arrival time for a car (in minutes since the beginning of the day). The operator can run the ferry whenever he or she wishes, but can take only the cars that have arrived up to that time.

Output

For each test case, output a single line with two integers: the time, in minutes since the beginning of the day, when the last car is delivered to the other side of the river, and the minimum number of trips made by the ferry to carry the cars within that time. 

You may assume that 0 < n, t, m < 1440. The arrival times for each test case are in non-decreasing order.

Sample Input

 

2

2 10 10
0
10
20
30
40
50
60
70
80
90
2 10 3
10
30
40

Sample Output

 

100 5

50 2

Source

最早到达对岸的时间,取决于最后一辆车的被运送时间,所以最优策略是让最后一辆车先走

就是一个贪心+dp

 

#include
int a[1445];int main(){ int T; scanf("%d",&T); while(T--) { int n,t,m; scanf("%d%d%d",&n,&t,&m); for(int i=1;i<=m;i++) scanf("%d",&a[i]); a[0]=-t*2; int x=m%n,s=a[x]; for(int i=1;i<=m/n;i++) { s+=t*2; if(a[n*i+x]>s)s=a[n*i+x]; } printf("%d %d\n",s+t,(m-1)/n+1); } return 0;}

 

 

 

转载于:https://www.cnblogs.com/BobHuang/p/7752941.html

你可能感兴趣的文章
多年一直想完善的自由行政审批流程组件【2002年PHP,2008年.NET,2010年完善数据设计、代码实现】...
查看>>
自动生成四则运算题目
查看>>
【前台】【单页跳转】整个项目实现单页面跳转,抛弃iframe
查看>>
数据库设计中的14个技巧
查看>>
Android学习系列(5)--App布局初探之简单模型
查看>>
git回退到某个历史版本
查看>>
ecshop
查看>>
HTML5基础(二)
查看>>
在GCE上安装Apache、tomcat等
查看>>
在Mac 系统下进行文件的显示和隐藏
查看>>
ue4(c++) 按钮中的文字居中的问题
查看>>
技能点
查看>>
读书笔记《乌合之众》
查看>>
Hadoop日记Day1---Hadoop介绍
查看>>
iOS 学习资料汇总
查看>>
centos7 yum安装jdk
查看>>
Bluedroid与BluZ,蓝牙测试方法的变动(基于bludroid和BlueZ的对比)
查看>>
接口和抽象类有什么区别
查看>>
zzzzw_在线考试系统①准备篇
查看>>
App Store 审核被拒的23个理由
查看>>