2419: Ferry Loading II 

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

Waterloo Jan.25 2003

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

就是一个贪心+dp

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

TOJ 2419: Ferry Loading II的更多相关文章

  1. POJ-2336 Ferry Loading II(简单DP)

    Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3763 Accepted: 1919 Desc ...

  2. poj 2336 Ferry Loading II ( 【贪心】 )

    Ferry Loading II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3704   Accepted: 1884 ...

  3. poj-2336 Ferry Loading II(dp)

    题目链接: Ferry Loading II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3946   Accepted: ...

  4. [POJ2336]Ferry Loading II

    题目描述 Description Before bridges were common, ferries were used to transport cars across rivers. Rive ...

  5. Ferry Loading III[HDU1146]

    Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. POJ 2609 Ferry Loading(双塔DP)

    Ferry Loading Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1807   Accepted: 509   Sp ...

  7. Ferry Loading II_贪心

    Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...

  8. Ferry Loading||

    uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  9. 【HDOJ】1406 Ferry Loading III

    模拟,注意需要比较队头与当前时间的大小关系. #include <cstdio> #include <cstring> #include <cstdlib> #de ...

随机推荐

  1. 流行的9个Java框架介绍: 优点、缺点等等

    流行的9个Java框架介绍: 优点.缺点等等 在 2018年,Java仍然是世界上最流行的编程语言.它拥有一个巨大的生态系统,在全世界有超过900万Java开发人员.虽然Java不是最直接的语言,但是 ...

  2. WPF之Binding【转】

    WPF之Binding[转] 看到WPF如此之炫,也想用用,可是一点也不会呀. 从需求谈起吧: 首先可能要做一个很炫的界面.见MaterialDesignInXAMLToolKit. 那,最主要的呢, ...

  3. 跨平台C++开源代码的两种常用编译方式

    作者:朱金灿 来源:http://blog.csdn.net/clever101 跨平台C++开源代码为适应各种编译器的编译,采用了两种方式方面来适配.一种是makefile方式.以著名的空间数据格式 ...

  4. uvm_comps.svh

    UVM的文件组织方式很有意思,比如,在src/comps/ 下的所有文件都通过uvm_comps.svh 包含进去. `include "comps/uvm_pair.svh" ` ...

  5. SQL根据出生日期精确计算年龄、获取日期中的年份、月份

    第一种: 一张人员信息表里有一人生日(Birthday)列,跟据这个列,算出该人员的年龄 datediff(year,birthday,getdate()) 例:birthday = '2003-3- ...

  6. C++拾遗(二)——初窥标准库类型

    本篇博文的开始,先介绍一道书上看到的智力题:有20瓶药丸,其中19瓶装有1克/粒的药丸,余下一瓶装有1.1克/粒的药丸.有一台称重精准的天平,只是用一次天平的情况下如何找出比较重的那瓶药丸? 好了,直 ...

  7. Linux远程连接及常用指令

    一.远程连接 一般,服务器都是特别庞大的,会把它们用一个独立的小屋进行存放,如果有时候需要对服务器进行一些操作,离得近还好,离的远就会破费一些周折了,所以,这个时候我们就需要用到远程连接软件了.推荐使 ...

  8. UVA 1412 Fund Management (预处理+状压dp)

    状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...

  9. CF 1119F Niyaz and Small Degrees

    打VP的时候由于CXR和XRY切题太快了导致我只能去写后面的题了 然而VP的时候大概还有一小时时想出了\(O(n^2\log n)\)的暴力,然后过了二十分钟才想到删点的优化 结果细节很多当然是写不出 ...

  10. (七)VMware Harbor 问题:Get https://192.168.3.135:8088/v2/: http:server gave HTTP response to HTTPS client

    (一)问题描述 登陆时,报错 docker Get https://192.168.3.135:8088/v2/: http:server gave HTTP response to HTTPS cl ...