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. ubuntu用户注销后登录xmodmap无法自动运行

    2015-12-17 21:34:50 还是无法解屏后 自动运行xmodmap ,继续谷歌找到一方法,选装gnome-tweak-tool sudo apt-get install gnome-twe ...

  2. SpringBoot学习笔记-Chapter2(hello word)

    开篇 第一次在博客园上写博客,初衷是想记录一下学习笔记,以往都是用笔去记录下学习笔记,现在来看在效率.检索速度上以及可可复制性都不好.作为一名Java开发人员 不会Spring Boot一定会被鄙视的 ...

  3. 初探ant design pro

    1.增加路由子页面&配置菜单 因为ant design pro采取的是umi路由配置,所以只要在对应的文件夹下新建相关的文件夹以及文件,它会自动解析.按照如下的步骤做即可 PS.如果想要给菜单 ...

  4. Android recyclerview 只显示一行 宽度不适配

    最近学习recyclerview 遇到的问题 1.宽度不适配 正确写法 LayoutInflater.from(context).inflate(R.layout.item_view,parent,f ...

  5. eclipse的hadoop插件对集群操作提示org.apache.hadoop.security.AccessControlException:Permission denied

    eclipse的hadoop插件对集群操作提示org.apache.hadoop.security.AccessControlException:Permission denied: user = z ...

  6. linux各文件夹的作用(转)

    转自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可 ...

  7. Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

    Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

  8. codevs 1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description CCC的足球比赛和传统的足球比赛有一点不同, 一次进球当且仅当先后接触到球的 ...

  9. codevs 2776 寻找代表元

     时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold     题目描述 Description 广州二中苏元实验学校一共有n个社团,分别用1到n编号.广州二中苏元实验 ...

  10. Nodejs + Jshint自动化静态代码检查

    1.   目的 提交代码前能够自动化静态代码检查,提高代码质量 2.   准备 1.    Nodejs安装: 官方地址:http://nodejs.org/ 安装说明:根据电脑配置下载对应的版本进行 ...