[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 ...
随机推荐
- 【转】ServletContext介绍及用法
1.1. 介绍 ServletContext官方叫servlet上下文.服务器会为每一个工程创建一个对象,这个对象就是ServletContext对象.这个对象全局唯一,而且工程内部的所有servl ...
- Unity编辑器扩展学习 转载
https://www.xuanyusong.com/archives/category/unity/unity3deditor 1 using UnityEngine; public class T ...
- RestController 能不能通过配置关闭
https://stackoverflow.com/questions/29958231/can-a-spring-boot-restcontroller-be-enabled-disabled-us ...
- IDEA帮助文档快捷键ctrl+q 查看类 方法 变量 帮助文档 注释 快捷键
IDEA查看类 成员变量 局部变量注释快捷键,Ctrl +Q 查看帮助文档 实际项目中,通常一个类中的代码都不少,而且有很多的变量 那么如何快速知道这个变量的一些信息,比如类型,定义? 比如在第50 ...
- Python getopt 模块
Python getopt 模块 getopt模块,是配合sys.argv使用的一个扩展.他可以接收终端的参数.格式扩展为“-n” 或 “--n”两种类型,下面是具体解释. 使用 improt get ...
- 一个人的公众号,我写了1w+
大家好,我是Bypass,一个人一直保持着写博客的习惯,为此维护了一个技术公众号,致力于分享原创高质量干货,写的内容主要围绕:渗透测试.WAF绕过.代码审计.应急响应.企业安全. 一直以来,我把它当成 ...
- ssl与ssh
openssl genrsa -out private_key.pem 1024 ssh-keygen -t rsa -C zzf073@163.com ssl是安全会话协商机制: ssh是安全访问机 ...
- SQL Server中,如何查看每个数据库的Owner是哪个SQL Server账户,也就是谁创建的
有时候我们作为SQL Server的DBA,会需要查找每个数据库的Owner是哪个SQL Server账户,也就是谁创建的. 我们可以使用系统存储过程"sys.sp_helpdb" ...
- C++矢量图形库系列(转)
转自:http://blog.sina.com.cn/s/blog_4265e1760100lg03.html 本系列篇章的主要内容是讲解矢量图形库的编译.开发和使用.并不对他们周边的内容做过多的描述 ...
- pyqt5学习
详细设计追函数报告生成 界面大致如下: 部分UI代码: #!/usr/bin/env python3.7 # -*- coding:utf-8 -*- # Author: Lancer 2019-09 ...