题目描述 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 Description

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 Description

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

数据范围及提示 Data Size & Hint

 

之前的一些废话:近日诸事不顺。

题解:首先把题目大意说一下:一个轮船它可以承载n辆车,它要把m辆车送到对岸,从此岸到彼岸需要的时间为t,给出m辆车的到达此岸的时间,问要把所有m辆车送到对岸需要最短的时间为多少?在最短的时间内最少可以多少趟完成任务。

dp(i)表示运完第i条船所需时间。从j=(i-n,i-1)转移而来,表示枚举每次运的辆数,dp[i]=max(a[i],dp[j])+2*t 转移过程中顺便完成对趟数的处理。

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define mem(a,b) memset(a,b,sizeof(a))
inline int read()
{
int x=,f=;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-;c=getchar();}
while(isdigit(c)){x=x*+c-'';c=getchar();}
return x*f;
}
const int maxn=,oo=;
int T,n,m,t,a[maxn],ans,ans1,dp[maxn],cnt[maxn];
int main()
{
T=read();
while(T--)
{
mem(dp,);mem(cnt,);ans1=ans=oo;
n=read();t=read();m=read();
for(int i=;i<=m;i++)a[i]=read();
dp[]=;cnt[]=;
for(int i=;i<=m;i++)
for(int j=max(,i-n);j<i;j++)
{
if(dp[i]>max(a[i],dp[j])+*t)
{
dp[i]=max(a[i],dp[j])+*t;
cnt[i]=cnt[j]+;
}
else if(dp[i]==max(a[i]-dp[j],)+*t)cnt[i]=min(cnt[i],cnt[j]+);
}
for(int i=max(,m-n);i<m;i++)ans=min(ans,max(dp[i],a[m])+t);
for(int i=max(,m-n);i<m;i++)ans1=min(ans1,cnt[i]+);
printf("%d %d\n",ans,ans1);
}
return ;
}

总结:

[POJ2336]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(dp)

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

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

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

  4. TOJ 2419: Ferry Loading II

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

  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. 入门理解mysql-binlog

    mysql-binlog简介: mysql的二进制日志记录了所有DDL和DML(除select) 开启binlog日志后会有1%左右的的性能损耗 二进制日志包括两类 索引文件 XXXX.index 日 ...

  2. centos上tcp抓包

    tcpdump host 10.1.131.75 -i eth0  -w data.cap 其中,10.1.131.75上目标机器的IP,eth0上网卡名称,data.cap上抓包数据写入的文件.

  3. 项目整合SpringDataRedis

    1:准备工作 先导入redis和jedis依赖,在配置redis-config.properties 和applicationContext-redis.xml (详细配置信息及入门demo见我上一篇 ...

  4. win10每次开机都会自检系统盘(非硬件故障)——解决方案2019.07.12

    1.最近反复遇到了这个问题,之前遇到这个问题就把系统重装了,没想到今天又遇到了,目前系统东西太多了,重装太麻烦了,就下决心解决一下. 2.不要使用网络上流传的修改注册表的方案,把注册表的那个键值删除那 ...

  5. 一些 Java 和 Android 的参考资料

    1. .net程序员转战android第三篇---登录模块之静态登录 2. .net程序员转战android第二篇---牛刀小试 3. .net程序员转战android第一篇---环境部署 4. 一些 ...

  6. SpringBoot与Swagger整合

    1 SpringBoot与Swagger整合https://blog.csdn.net/jamieblue1/article/details/99847744 2 Swagger详解(SpringBo ...

  7. C# if else-if 语句

    一.作用 用来处理多条件的区间性的判断. 二.语法 if(判断条件) { 要执行的代码; } else if(判断条件) { 要执行的代码; } else if(判断条件) { 要执行的代码; } e ...

  8. 渗透常见linux命令

    在拿到一个 webshell 之后,大家首先会想到去把自己的权限提升到最高,windows 我们会提升到 SYSTEM 权限,而 Linux 我们会提升到 root 权限,拿在进行 Linux 提权的 ...

  9. Qt压缩和解压 zip

    zlib编译详见 https://blog.csdn.net/zhangxuechao_/article/details/85049711 下载quazip https://github.com/st ...

  10. js中console在一行内打印字符串和对象

    在前端开发中,大多数的调试一般都是F12中的console和network中查看请求数据和响应数据,也有一部分人喜欢用debugger. 在开发大一些的项目时,在开发环境下,打开着控制台,切换一下页面 ...