若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1146: Ferry Loading II

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,324

题目描述

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?
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. 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.

输入

暂无

输出

暂无

样例输入

2
2 10 10
0
10
20
30
40
50
60
70
80
90
2 10 3
10
30
40

样例输出

100 5
50 2

参考代码

#include <stdio.h>
int f,i,k,m,n,t,c,nf,leave[2000];
main() 
{
    scanf("%d",&c);
    while (c--) 
    {
        scanf("%d%d%d",&n,&t,&m);
        t *= 2;
        nf = (m+n-1)/n;
        k = m - (nf-1) * n;
        for (i=0;i<k;i++) scanf("%d",&leave[0]);
        for (f=1;f<nf;f++) 
        {
            for (i=0;i<n;i++) scanf("%d",&leave[f]);
        }
        for (f=0;f+1<nf;f++) 
        {
            if (leave[f]+t > leave[f+1]) leave[f+1] = leave[f]+t;
        }
        printf("%d %dn",leave[nf-1]+t/2,nf);
   }
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Dreams孤独患者 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist