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

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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int et[1500]; int main()
{
int n, t, m;
int caset;
scanf("%d", &caset );
int i, j;
while(caset--)
{
scanf("%d %d %d", &n, &t, &m);
for(i=1; i<=m; i++)
{
scanf("%d", &et[i] );
} //最早到达对岸的时间,取决于最后一辆车的被运送时间
//最优解是最后一辆车能够被尽早的运走 int dd, ff;
dd=m % n;
ff=m / n;
int ans=0, cnt=0;
if(dd!=0){
ans = et[dd];
ans = ans+t*2;
cnt++;
}
for(i=dd+n; i<=m; )
{
if( ans< et[i])
ans=et[i];
ans = ans+2*t;
i=i+n;
cnt++;
}
printf("%d %d\n", ans-t, cnt++ ); }
return 0;
}
												

poj 2336 Ferry Loading II ( 【贪心】 )的更多相关文章

  1. TOJ 2419: Ferry Loading II

    2419: Ferry Loading II  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Subm ...

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

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

  3. poj-2336 Ferry Loading II(dp)

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

  4. POJ 2609 Ferry Loading(双塔DP)

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

  5. Ferry Loading II_贪心

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

  6. POJ 2609 Ferry Loading

    双塔DP+输出路径. 由于内存限制,DP只能开滚动数组来记录. 我的写法比较渣,但是POJ能AC,但是ZOJ依旧MLE,更加奇怪的是Uva上无论怎么改都是WA,其他人POJ过的交到Uva也是WA. # ...

  7. [POJ2336]Ferry Loading II

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

  8. Ferry Loading III[HDU1146]

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

  9. AtCoder - agc043_a 和 POJ - 2336 dp

    题意: 给你一个n行m列由'#'和'.'构成的矩阵,你需要从(1,1)点走到(n,m)点,你每次只能向右或者向下走,且只能走'.'的位置. 你可以执行操作改变矩阵: 你可以选取两个点,r0,c0;r1 ...

随机推荐

  1. 【音乐App】—— Vue-music 项目学习笔记:歌曲列表组件开发

    前言:以下内容均为学习慕课网高级实战课程的实践爬坑笔记. 项目github地址:https://github.com/66Web/ljq_vue_music,欢迎Star. 当前歌曲播放列表 添加歌曲 ...

  2. API接口管理工具postman等

    国外 postman Swagger:国外比较流行的一款管理工具,英文配置,需要一定的英文基础和服务器搭建基础,学习成本较高. 国内 Apizza: 风格类似postman,熟悉postman的会比较 ...

  3. HTML5 Canvas 绘制旋转45度佛教万字

    效果如下: 代码如下: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Cont ...

  4. .net 定时执行 windows 服务

    1.新建项目 --> Windows 服务 2.Service1.cs代码 using System; using System.Collections.Generic; using Syste ...

  5. BCG菜单button的简单使用

    一,新建一个BCGprojectCBCGPMenuButton,基于对话框. 二.添加一个button,并关联一个CButton类型的变量m_btn1.然后手动将类型改CBCGPMenuButton成 ...

  6. SOCKIT 在make时出现(target pattern contains no % stop)???

    Make错误(***target pattern contains no % stop) 1.   问题描述 在按照SoC_SW_Lab_13.0.pdf操作时候出现了下列图片的错误 2.   Bsp ...

  7. 【问】Windows下C++局部变量在内存中的分布问题

    原本是为了看看C++对象模型中子对象赋值给一个父对象和父类型指针指向的域时,到底会不会切割,就打开codebloks写了下面的代码,编译器选的是GNU. #define DEBUG(X) std::c ...

  8. leetcode笔记:Pow(x, n)

    一. 题目描写叙述 Implement pow(x, n). 二. 题目分析 实现pow(x, n).即求x的n次幂. 最easy想到的方法就是用递归直接求n个x的乘积,这里须要依据n的值,推断结果是 ...

  9. linux 安装mongo

    在Linux中安装Mongodb操作说明 MongoDB配置 版本说明:因本机所装Red Hat 为 64位操作系统故本例以64位的MongDB为例.所用版本如下: (1)    Red Hat En ...

  10. 多线程快速解压FastZipArchive介绍

    本文转载至  http://blog.csdn.net/xunyn/article/details/12975937   多线程解压iosfast 在iOS项目中用到解压缩,用的是ZipArchive ...