用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

Mpq

博客信息

积分:988
等级:4级 lv 4
日志总数:231
发表评论总数:18 ( 查看)
获得评论总数:21
发表留言总数:0
所属学校:三鑫
收藏本站:

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

--游客
好文好文,是您的手笔?如果是您的文章,如果您愿意和我联系,...
还有就是数学不能使用计算器…….......在读初中之前原...
--Mpq
这次似乎不举行冬季长跑……看来在三鑫参加的体育项目最终是以...
--Mpq
看了你的"总结", 挺有针对性的! 相信下学期你一定会有...

RSS


首页 -> Zoj题库->Ferry Loading II
Ferry Loading II

Ferry Loading II


Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 121   Accepted Submit: 58  


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
 
 
 
Program Zoj_1918_Mpq;
Const Maxn=1440;
var
  n,m,t,tt,answer:longint;
  time:array[1..Maxn] of integer;
  f:array[0..Maxn,1..Maxn] of integer;
procedure init;
var
  i:integer;
begin
  readln(n,t,m);
  for i:=1 to m do readln(time[i]);
end;
function Min(a,b:integer):integer;
begin
  if a<b then exit(a) else exit(b);
end;
procedure Dp;
var
  i,j,k,tmp,tot:longint;
begin
  fillchar(f,sizeof(f),60);
  for i:=1 to n do
    f[1,i]:=time[i]+2*t;
  for i:=2 to m do
    for j:=i to Min(m,j*i) do
      for k:=j-1 downto i-1 do
      begin
        if j-k>n then break;
        if f[i-1,k]>=time[j] then
           tmp:=0 else
           tmp:=time[j]-f[i-1,k];
        f[i,j]:=Min(f[i,j],f[i-1,k]+t*2+tmp);
      end;
  answer:=Maxint;
  if m mod n=0 then n:=m div n else n:=m div n+1;
  for i:=n to m do
    if f[i,m]<answer then
    begin
      answer:=f[i,m];
      tot:=i;
    end;
  writeln(answer-t,' ',tot);
end;
begin
  readln(tt);
  for tt:=1 to tt do
  begin
    init;
    Dp;
  end;
end.

网友评论

共 0 页,0 条记录  

用户名:
密码:
您的评论:
正在载入编辑器...
请输入验证码:


发 表 评 论

Mpq-中山教师家园