SDAU课程练习--problemO(1014)
题目描述
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条船及其到达渡口的时间表。求最早运送的时间及最少次数。
解题思路
- 则总时间 = 最后一辆车的到达时间+最后一辆车的等待时间+单程时间
- 问题转化为求最后一辆车的最小等待时间
#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;bool cmp(int a, int b){return a > b;}int a[1500];int main(){ios::sync_with_stdio(false);//freopen("date.in", "r", stdin);//freopen("date.out", "w", stdout);int N = 0, n = 0, t = 0, m = 0,count=0,time=0;cin >> N;for (int i = 0; i < N; i++){count = 0;time = 0;cin >>n>> t >> m;for (int j = 1; j <= m; j++){cin>>a[j];}//sort(a, a + n, cmp);if (n >= m){count = 1;time = a[m]+2 * t;}else{if (m%n==0){count = m / n;for (int l = n; l <= m; l += n){time = max(a[l], time);time += (2 * t);}}else {count = m / n + 1;time = a[m%n] + 2 * t;//time = a[1] + 2 * t;for (int k = m%n + n; k <= m; k += n){time = max(a[k], time);time += (2 * t);}}}cout << time-t << " " << count << endl;}return 0;}
SDAU课程练习--problemO(1014)的更多相关文章
- SDAU课程练习--problemQ(1016)
题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...
- SDAU课程练习--problemG(1006)
题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...
- SDAU课程练习--problemB(1001)
题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...
- SDAU课程练习--problemA(1000)
题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...
- SDAU课程练习--problemC
题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...
- SDAU课程练习--problemE
problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...
- 数据结构与算法课程作业--1014. Translation
这道题思想很简单,就是用map将foreign的作为键值,english的值作为对应的映射值,然后通过直接用foreign作为map对象的下标直接查找. 本题比较烦人的一点就是输入数据,我使用了get ...
- 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 ...
- 20165325 2017-2018-2《Java程序设计》课程总结
20165325 2017-2018-2<Java程序设计>课程总结 一.每周作业链接汇总 1.预备作业一:我期待的师生关系 20165325 期望的师生关系 简要内容: 我心中的好老师 ...
随机推荐
- Windows如何压缩tar.gz格式
Windows如何压缩tar.gz格式 tar.gz 是linux和unix下面比较常用的格式,几个命令就可以把文件压缩打包成tar.gz格式 然而这种格式在windows并不多见,WinRAR.Wi ...
- 注解 @ 或者 Alt+/ 不提示 或者提示 no default propsals 解决方案
- Entity Framework技巧系列之七 - Tip 26 – 28
提示26. 怎样避免使用不完整(Stub)实体进行数据库查询 什么是不完整(Stub)实体? 不完整实体是一个部分填充实体,用于替代真实的对象. 例如: 1 Category c = new Cate ...
- how to add a shared lib in C?
http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html Basically, 2 steps: 1) make the ...
- why TCP guarentee delivery?
Simple idea: just use a TIMEOUT, if no answer after a certain seconds, just re-deliver!
- centos精简系统 源码安装客户端git
CentOS的yum源中git版本比较低,需要最新版本git,只能自己编译安装,现在记录下编译安装的内容,留给自己备忘. 对于精简型的centos系统,会缺少很多依赖包和插件,要源码安装客户端git, ...
- jquery给html元素添加内容
append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() - 在被选元素之前插入内容 实例 $(& ...
- 转: Windows如何打开和使用事件查看器管理计算机
方法/步骤 1 右键单击"我的电脑"(win8中名称为"这台电脑.This Computer"),选择"管理",点击. 步骤阅读 2 出 ...
- dfs手写栈模板
在竞赛中如果系统栈很小的话,过深的递归会让栈溢出,这个时候我们就要自己手写栈,将递归转化成手工栈. 方法其实也很简单. 基本思路上,我们就是用栈不断的pop,push.但是何时push,何时pop呢? ...
- 转:用C语言的rand()和srand()产生伪随机数的方法总结
标准库<cstdlib>(被包含于<iostream>中)提供两个帮助生成伪随机数的函数: 函数一:int rand(void): 从srand (seed)中指定的seed开 ...