题目描述

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. VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法

    问题 : 在用VS2008写一段代码,算法都没有问题,但是调试的时候发现出了main之后就报 Stack around the variable 'xxx' was corrupted 的错误,后来发 ...

  2. HTTP 返回状态值详解

    当用户点击或搜索引擎向网站服务器发出浏览请求时,服务器将返回Http Header Http头信息状态码,常见几种如下: 1.Http/1.1 200 OK 访问正常  表示成功访问,为网站可正常访问 ...

  3. svn“Previous operation has not finished; run 'cleanup' if it was interrupted

    今天碰到了个郁闷的问题,svn执行clean up命令时报错“Previous operation has not finished; run 'cleanup' if it was interrup ...

  4. 关于getchar()的知识

    char* s1 = "123",字符串"123"这段内存是只读的,就是说其内容不能改变///char *s 这个是指申请一个地址空间 记录一个地址 #incl ...

  5. 昨天上架出现问题,you binary is not optimized for iphone5.。。。。

    这个时候只需要加一个lanuch image 就可以了

  6. PS:抠图方法1(利用对比度ctrl+l)

    PS:抠图方法1(利用对比度ctrl+l) 工具/原料   Photoshop.美女照片 方法/步骤     小编使用的是Photoshop cs5版本,大家使用其他版本都没有关系,界面略有不同,但操 ...

  7. Android sdk content loader

    方法一(关闭后重启): 遇到Eclipse右下角一直显示“Android sdk content loader 0%”的情况时,直接关掉Eclipse,有ADB进程在运行时通过进程管理器结束进程,然后 ...

  8. iOS 10推送通知开发

    原文地址:Developing Push Notifications for iOS 10,译者:李剑飞 虽然通知经常被过度使用,但是通知确实是一种获得用户关注和通知他们需要更新或行动的有效方式.iO ...

  9. 12c meet sysdba meet ORA-01017: invalid username/password; logon denied

    checklist: 1.12c: threaded_execution=true Prevents OS Login As Sysdba 2. The following database para ...

  10. Hibernate 系列教程3-单表操作

    工程截图 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Conf ...