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. Java语言中自动生成随机数

    参考原文:http://zhidao.baidu.com/link?url=nB3BT69wmUAiSPfKGgK5Q7HOFFP9AIE04AthreRd9yYcwKhUQsQRWlMdMhW1Qm ...

  2. eureka集群环境搭建

    一:集群环境搭建 第一步:我们新建两个注册中心工程一个叫eureka_register_service_master.另外一个叫eureka_register_service_backup eurek ...

  3. CommonJS与ES6、AMD、CMD比较

    Javascript,javascript是一种脚本编程语言,有自己独立的语法与语义,没有javascript,也就没有其他的那些概念了. 关于ES6,可直接理解为javascript的增强版(增加了 ...

  4. Android WiFi使用记录

    最近在做Android的WiFi部分的开发,连接的工具类参照了这个文章的工具类. http://www.cnblogs.com/zhuqiang/p/3566686.html 开发中碰上的一些问题,在 ...

  5. python-mysql软件下载地址

    http://sourceforge.net/projects/mysql-python/?source=dlp

  6. iphone之打开pdf、doc、xls文件用UIWebView

    //文件名字及类型 NSString *path=[[NSBundle mainBundle]pathForResource:@"xls1" ofType:@"xls&q ...

  7. Git 学习教程【转+总结】

    之前是在用SVN,现在因为小伙伴比较喜欢Git,所以也开始学习Git,很感谢 时光穿梭机 - 廖雪峰 的无私奉献.本文用来记录我在学习Git过程中的收获和笔记,廖雪峰大神的Git教程参考这里. 1.G ...

  8. Mybatis配置多数据源

    一. Spring配置多数据源 二. Spring配置数据源 三. MultipleDataSource的实现 1: package com.wbl.modal; 2:  3: import org. ...

  9. LR中常见请求的使用示例

    Action(){ //application/x-www-form-urlencoded //application/json //web_add_auto_header("Content ...

  10. codevs 1008 选数

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n ...