[POJ2336]Ferry Loading II
|
题目描述 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. |
|
输入描述 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 |
|
样例输出 Sample Output |
100 5 |
|
数据范围及提示 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的更多相关文章
- POJ-2336 Ferry Loading II(简单DP)
Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3763 Accepted: 1919 Desc ...
- poj-2336 Ferry Loading II(dp)
题目链接: Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3946 Accepted: ...
- poj 2336 Ferry Loading II ( 【贪心】 )
Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3704 Accepted: 1884 ...
- TOJ 2419: Ferry Loading II
2419: Ferry Loading II Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Subm ...
- Ferry Loading III[HDU1146]
Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 2609 Ferry Loading(双塔DP)
Ferry Loading Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1807 Accepted: 509 Sp ...
- Ferry Loading II_贪心
Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...
- Ferry Loading||
uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...
- 【HDOJ】1406 Ferry Loading III
模拟,注意需要比较队头与当前时间的大小关系. #include <cstdio> #include <cstring> #include <cstdlib> #de ...
随机推荐
- 获取Kafka每个分区最新Offset的几种方法
目录 脚本方法 Java 程序 参考资料 脚本方法 ./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhos ...
- Comment file
/// This is the head comment of a file. /*********************************************************** ...
- pycharm的安装与破解
一.首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载PyCharm安装包,根据自己 ...
- 车位iou计算
车位检测中,判断多帧图像检测出的车位是否是同一个车位.计算其IOU. 判断一个点是否在一个四边形内 Approach : Let the coordinates of four corners be ...
- 【论文阅读】Objects as Points 又名 CenterNet | 目标检测
目录 Abstract Instruction 分析 CenterNet 的Loss公式 第一部分:\(L_k\) 第二部分:\(L_{size}\) 第三部分:\(L_{off}\) Abstrac ...
- CodeFirst开发方式创建数据库
1).新建ADO.NET实体数据模型--->选择空CodeFirst模型 2).新建两个实体类(客户表和订单信息表) using System; using System.Collections ...
- ASP.NET Core 发布到Linux需要注意的地方
此文持续更新. 读取本地目录的问题, 在windows下,一般会用“\”,但在Linux中用的是“/” 待续..
- Python - 错误和异常 - 第十九天
Python 错误和异常 作为 Python 初学者,在刚学习 Python 编程时,经常会看到一些报错信息,在前面我们没有提及,这章节我们会专门介绍. Python 有两种错误很容易辨认:语法错误和 ...
- jenkins19年最新最管用的汉化
今天准备学学jenkins ,官方下载了一个最新版本,发现是英文版,网上找个许多汉化方式,几乎都是一种,下载插件 :Locale plugin ....很尴尬,下载完了还是没有汉化 ,是不是jenki ...
- 构建maven项目,自定义目录结构方法
构建maven项目 创建自定义的文件目录方法: 在项目名称右键-->Builder Path-->Configure Builder Path...Source菜单下的Add Folder ...