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 期望的师生关系 简要内容: 我心中的好老师 ...
随机推荐
- 解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载
解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载 当这两个头文件顺序颠倒时,编译会出现许多莫名其妙的错误,错误如下: 1>…\include\ws2def.h( ...
- OpenLDAP安装与配置
系统:ubuntu 14.04 安装: 1. sudo apt-get install slapd ldap-utils 2. 在1的过程中会让你输了admin密码 配置: 如果安装过,只是想配置Op ...
- git(工作区,暂存区,管理修改,撤销修改,删除文件)
工作区和暂存区 984次阅读 Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的l ...
- openwrt下加载snmp模块
加snmp模块到openwrt中去 1.下载snmp的解压包文件 net-snmp-5.4.2.1.tar.gz 下载地址为:http://www.net-snmp.org/download.html ...
- Spring Security3实现,权限动态获取
Spring Security3实现,权限动态获取 原文 http://blog.csdn.net/yangwei19680827/article/details/9359113 主题 网络安全Sp ...
- php添加gd
一 GD简介: php处理图形的扩展库,提供了一系列用来处理图片的API.如果开发过程中发现有页面验证码不能显示,则要考虑检查phpinfo(),是否支持GD库. 二 思路: 网上发现添加GD库的方法 ...
- postfix日志分析pflogsumm
1.pflogsumm功能:统计接收.投递.转发.延时.反弹.拒绝.保留.丢弃的邮件统计发件人和收件人 统计发送和接受方主机/域名 统计SMTPD连接数...... 2.安装# yum install ...
- 【转】4G手机打电话为什么会断网 4G上网和通话不能并存原因分析
与2G/3G相比,4G最大的特色就是提供了超过100Mbps的峰值速率,既然速度都可以秒掉20M的光纤固网了,那用来语音通话不就更是小菜一碟了吗?很遗憾,问题就出现在了这里. 由于目前的LTE网络(4 ...
- 转 Oracle 12c 使用scott等普通用户的方法
一.前言 最近电脑上安装了oracle 12c数据库,想体验下新特性.安装完后,便像11g一样在dos窗口进行下面的操作: SQL*Plus: Release 12.1.0.2.0 Productio ...
- 【二分图】 poj 1466
#include <iostream> #include <memory.h> #include <cstdio> using namespace std; int ...