题目描述

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

题目大意

渡口的船每次运n条船,过一次河用时t。给定m条船及其到达渡口的时间表。求最早运送的时间及最少次数。

解题思路

  • 则总时间 = 最后一辆车的到达时间+最后一辆车的等待时间+单程时间
  • 问题转化为求最后一辆车的最小等待时间
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. using namespace std;
  5. bool cmp(int a, int b)
  6. {
  7. return a > b;
  8. }
  9. int a[1500];
  10. int main()
  11. {
  12. ios::sync_with_stdio(false);
  13. //freopen("date.in", "r", stdin);
  14. //freopen("date.out", "w", stdout);
  15. int N = 0, n = 0, t = 0, m = 0,count=0,time=0;
  16. cin >> N;
  17. for (int i = 0; i < N; i++)
  18. {
  19. count = 0;
  20. time = 0;
  21. cin >>n>> t >> m;
  22. for (int j = 1; j <= m; j++)
  23. {
  24. cin>>a[j];
  25. }
  26. //sort(a, a + n, cmp);
  27. if (n >= m)
  28. {
  29. count = 1;
  30. time = a[m]+2 * t;
  31. }
  32. else
  33. {
  34. if (m%n==0)
  35. {
  36. count = m / n;
  37. for (int l = n; l <= m; l += n)
  38. {
  39. time = max(a[l], time);
  40. time += (2 * t);
  41. }
  42. }
  43. else {
  44. count = m / n + 1;
  45. time = a[m%n] + 2 * t;
  46. //time = a[1] + 2 * t;
  47. for (int k = m%n + n; k <= m; k += n)
  48. {
  49. time = max(a[k], time);
  50. time += (2 * t);
  51. }
  52. }
  53. }
  54. cout << time-t << " " << count << endl;
  55. }
  56. return 0;
  57. }

SDAU课程练习--problemO(1014)的更多相关文章

  1. SDAU课程练习--problemQ(1016)

    题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...

  2. SDAU课程练习--problemG(1006)

    题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...

  3. SDAU课程练习--problemB(1001)

    题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...

  4. SDAU课程练习--problemA(1000)

    题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...

  5. SDAU课程练习--problemC

    题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...

  6. SDAU课程练习--problemE

    problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...

  7. 数据结构与算法课程作业--1014. Translation

    这道题思想很简单,就是用map将foreign的作为键值,english的值作为对应的映射值,然后通过直接用foreign作为map对象的下标直接查找. 本题比较烦人的一点就是输入数据,我使用了get ...

  8. acm课程练习2--1013(同1014)

    题目描述 There is a strange lift.The lift can stop can at every floor as you want, and there is a number ...

  9. 20165325 2017-2018-2《Java程序设计》课程总结

    20165325 2017-2018-2<Java程序设计>课程总结 一.每周作业链接汇总 1.预备作业一:我期待的师生关系 20165325 期望的师生关系 简要内容: 我心中的好老师 ...

随机推荐

  1. leetcode342合理运用位操作判断4的幂

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...

  2. H5调用本地摄像头

    <!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...

  3. UI篇—UITableview

    一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UITableView继承自UIScrollView,因此支 ...

  4. 关于用模拟器运行百度地图API无法定位的问题 - 不能用模拟器

    模拟器是没有办法定位,当你加入定位模块的时候,传出的参数都是空的. 定位的这个方法函数,是通过回调接口来实现,而且触发该事件的时候,需要经纬度位置改变.官方文档写得很清楚,简单点来说,就是你没有GPS ...

  5. .htaccess重写URL讲解

    使用ThinkPHP和Laravel等框架的都知道,所以的请求都需要经过index.php文件入口,无论你的URI是什么. 当然除了访问的是静态文件或者访问路径的文件真实存在,例如你访问xxx.com ...

  6. FreeRTOS中断优先级配置(重要)

    FreeRTOS中断优先级配置(重要) 本章节为大家讲解FreeRTOS中断优先级配置,此章节非常重要,初学者经常在这里犯迷糊.对于初学者来说,本章节务必要整明白.12.1 NVIC基础知识12.2  ...

  7. 详细的SQL中datediff用法

    DATEDIFF 函数 [日期和时间] 功能返回两个日期之间的间隔. 语法DATEDIFF ( date-part, date-expression-1, date-expression-2 ) da ...

  8. sql优化__rownum的使用【转】

    ROWNUM的概念ROWNUM是一个虚假的列.它将被分配为 1,2,3,4,...N,N 是行的数量.一个ROWNUM值不是被永久的分配给一行 (这是最容易被误解的).表中的某一行并没有标号:你不可以 ...

  9. Sea Battle

    Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  10. WPF中静态引用资源与动态引用资源的区别

    WPF中静态引用资源与动态引用资源的区别   WPF中引用资源分为静态引用与动态引用,两者的区别在哪里呢?我们通过一个小的例子来理解. 点击“Update”按钮,第2个按钮的文字会变成“更上一层楼”, ...