题目链接:

Ferry Loading II

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3946   Accepted: 1985

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 题意: 给m辆车的到达岸边的时间,现在给你一个轮渡能运车的数量,和单程的时间,现在问把这些车运过去的最短时间是多少,在这个时间中的 最少运送次数是多少? 思路: dp[i]表示运送前i个要用的时间,num[i]表示在dp[i]的时间内的最少次数;相邻的车在一块运,转移方程看代码吧; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=2e3+14;
const double eps=1e-12; int a[maxn],dp[maxn],num[maxn]; int main()
{
int T;
read(T);
while(T--)
{
int n,m,t;
read(n);read(t);read(m);
For(i,1,m)read(a[i]);
For(i,1,m)dp[i]=inf,num[i]=0;
dp[0]=0;
num[0]=0;
For(i,1,m)
{
for(int j=max(0,i-n);j<i;j++)
{
if(j==0){dp[i]=a[i]+t,num[i]=1;continue;}
if(dp[i]>max(dp[j]+t,a[i])+t)dp[i]=max(dp[j]+t,a[i])+t,num[i]=num[j]+1;
else if(dp[i]==max(dp[j]+t,a[i])+t)num[i]=min(num[i],num[j]+1);
}
}
cout<<dp[m]<<" "<<num[m]<<"\n";
}
return 0;
}

  

最新文章

  1. Modify Branding of FreeCAD
  2. iOS中空字符串报错
  3. 大端字节序&amp;小端字节序(网络字节序&amp;主机字节序)
  4. iPad版微信终于来临了 微信5.4版搜索更智能 转账就是发消息
  5. linq查询一个字段的总和
  6. Jquery Ajax调用aspx页面方法
  7. HC蓝牙模块测试AT指令搭建外部电路遇到的问题
  8. 嵌入式jetty
  9. DataGuard体系结构
  10. Implement Queue using Stacks 解答
  11. 【译】ASP.NET MVC 5 教程 - 1:入门
  12. 嗯,这个BLOG其实是个更新服务器
  13. sqlserver 经典入门基础书籍
  14. dubbo服务治理中间件,zookeeper注册中心
  15. 分布式进阶(二)Ubuntu 14.04下安装Dockr图文教程(一)
  16. C语言如何分离一个数的高低位,如何将2个字节变成一个字节
  17. SpringBoot + Spring Security 学习笔记(三)实现图片验证码认证
  18. Leviticus
  19. JDBC辅助类封装 及应用
  20. jenkins+maven+gitlab触发构建

热门文章

  1. 使用JDK中的类URL访问HDFS(来自吴超Hadoop)
  2. 数据存储之Archiver、Unarchiver、偏好设置
  3. Android 中保存全局变量
  4. jQuery--基础(实例)
  5. php迭代器模式
  6. 完好用户体验: 活用window.location与window.open解决页面跳转问题
  7. centOS中如何修改运行级别!
  8. Socket的UDP协议在erlang中的实现
  9. [转]Unity3D Editor 编辑器简易教程
  10. Tomcat学习笔记【4】--- Server.xml配置文件详解