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

总结:

最新文章

  1. React 其实比 MVVM 架构更加卡顿
  2. PopupWindow底部弹出
  3. ios 修改webView字体
  4. Java攻城狮面试考题
  5. Custom PeopleSoft Queries
  6. Oracle DBLINK 抽数以及DDL、DML操作
  7. Control character in cookie value, consider BASE64 encoding your value
  8. 基于Linux的oracle数据库管理 part4( shell管理 上 )
  9. string 对象及其操作
  10. Comparator TreeSet
  11. shell中的环境变量
  12. 安装程序时出现错误代码0x80070422
  13. Tomcat使用常见问题
  14. SAP中常用SM系列事务代码总结
  15. RUP 方法简介
  16. 手机号验证正则表达式+Demo(亲测完毕)
  17. 向量空间模型(Vector Space Model)的理解
  18. idea执行mapreduce报错 Could not locate Hadoop executable: C:\hadoop-3.1.1\bin\winutils.exe
  19. Centos6.5 防火墙开放端口
  20. django 执行 python manage.py makemigrations 报错

热门文章

  1. VBA基础 - 数据类型
  2. 关于书籍《区块链以太坊DApp开发实战》的内容告示
  3. Azure CosmosDB (14) 使用Postman访问CosmosDB REST API
  4. 聊一下,前后分离后带来的跨域访问和cookie问题
  5. Leetcode算法题 7. Reverse Integer2
  6. win10每次开机都会自检系统盘(非硬件故障)——解决方案2019.07.12
  7. 阿里云 .NET SDK Roa 和 Rpc 风格签名
  8. linux 修改文件的时间属性
  9. MySQL优化常见Extra分析——慢查询优化
  10. 转 Yolov3转化Caffe框架详解