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 期望的师生关系 简要内容: 我心中的好老师 ...
随机推荐
- JavaScript中以构造函数的方式调用函数
转自:http://www.cnblogs.com/Saints/p/6012188.html 构造器函数(Constructor functions)的定义和任何其它函数一样,我们可以使用函数声明. ...
- eclipse使用外部maven时multiModuleProjectDirectory错误解决
错误提醒: -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment vari ...
- nopcommerce插件相关
注意Description.txt中,以下字段必须配置当前可用.我抄人家代码的时候,人家是3.4 我也配成3.4,结果我的nop是3.7的,后台半天显示不出来插件,浪费了一下午.
- 设置ubuntu 默认不启动图形界面
设置ubuntu 默认不启动图形界面 一. 编辑文件/etc/X11/default-display-manager 如果值为/usr/sbin/gdm,则进入图形界面如果值为false,则进入控制台 ...
- unity3d自带帮助文档的打开方法
1废话不提,直接上图: 2.在弹出来的浏览器窗口中点击: 3.在点击后的网页中即可以搜索了,在断网的情况下,作为资料查询还是蛮不错的.
- 快速玩转Apple Pay开发
快速玩转Apple Pay开发 更新时间:2016年02月20日09时25分 来源:传智播客 Apple Pay 2016年2月18日上午,苹果公司宣布,与中国银联达成合作,正式在中国大陆上线Appl ...
- php非阻塞
PHP非阻塞模式 让PHP不再阻塞当PHP作为后端处理需要完成一些长时间处理,为了快速响应页面请求,不作结果返回判断的情况下,可以有如下措施: 一.若你使用的是FastCGI模式,使用fastcgi_ ...
- GDB调试程序常用命令
1.在xv6 内核中 通过 nm kernel | grep _start 找到kernel的起始地址是0010000c 8010b50c D _binary_entryother_start 801 ...
- SQLite错误总结 error code 19: constraint failed
SQLite错误总结 1. android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed错误原 ...
- Ubuntu下安装Reids
安装 官网 http://redis.io/ 下载安装包 redis-3.0.5.tar.gz 解压 tar -zxvf redis-3.0.5.tar.gz cd redis-3.0.5 安 ...