Problem Description
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. < br><
br>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,并且回来也需要时间t,共有m辆车,求最少拌匀次数,且此时的用时。
解题思路:最少搬运次数不用想就是m%n?m/n+1:m/n;至于半时间如果m%n为零就就直接排好序之后每次搬n辆,要不的话就先把m%n搬走,让后面的车尽可能的少等;
感悟:做多了也没啥感悟了,最难的地方就是想贪心的条件;
代码(G++)
#include

#include

#define maxn 1444

using namespace std;

int main()

{

   
//freopen("in.txt", "r", stdin);

    int
c,t,n,m,wait_time[maxn],times=0,time=0,lost_car=0;

   
scanf("%d",&c);

    for(int
i=0;i

    {

       
time=times=0;

       
scanf("%d%d%d",&n,&t,&m);

       
//printf("n=%d t=%d m=%d\n",n,t,m);

       
for(int j=1;j<=m;j++)

           
scanf("%d",&wait_time[j]);

       
lost_car=m%n;

       
times=m%n?m/n+1:m/n;//最少运输的次数;

if(lost_car)

           
time=wait_time[lost_car]+t*2;

       
//printf("此时时间是%d\n",time);

       
for(int j=1;j<=m/n;j++)//总共运times次;

       
{

           
//printf("wait_time[j*n+lost_car]=%d\n",wait_time[j*n+lost_car]);

//printf("time=%d\n",time);

           
if(time

           
{

               
time+=2*t+(wait_time[j*n+lost_car]-time);

               
if(j==m/n)

                   
time-=t;//最后一次不用回去了

           
}

           
else//现在有车了

           
{

               
time+=2*t;

               
if(j==m/n)

               
time-=t;//最后一次不用回去了

           
}

           
//printf("此时时间是%d\n",time);

       
}


       
printf("%d %d\n",time,times);

    }

}

Problem O的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. 阿里云linux centos 一键部署web环境--图文详解

    一.购买阿里云服务器ECS 1,登录阿里云,选择阿里云服务器ECS 2,创建实例 或 3,选好配置 4,完成配置 注:记住用户名和密码 二.一键配置linux环境 1,下载xshell,安装成功后,建 ...

  2. 树状数组(Binary Indexed Tree,BIT)

    树状数组(Binary Indexed Tree) 前面几篇文章我们分享的都是关于区间求和问题的几种解决方案,同时也介绍了线段树这样的数据结构,我们从中可以体会到合理解决方案带来的便利,对于大部分区间 ...

  3. String类的构造方法(2)

    写了常见的几个而已. 1:new 一个String类的时候系统会自动传一个空构造 public String(); 注意: 当对象初始化是 null时 和 对象是 "" 时,两者是 ...

  4. 关于使用git和github的一点点感想

    第二篇博客 首先附上我的第一个java程序github地址: https://github.com/KingsC123456/FirstJavaHello 其次是关于我的github介绍,因为一直使用 ...

  5. 树状数组初步_ZERO

    原博客:树状数组 1 一维树状数组 1 什么是树状数组        树状数组是一个查询和修改复杂度都为log(n)的数据结构,假设数组A[1..n],那么查询A[1]+-+A[n]的时,间是log级 ...

  6. DOM中元素对象的属性方法

    在 HTML DOM (文档对象模型)中,每个部分都是节点. 节点是DOM结构中最基本的组成单元,每一个HTML标签都是DOM结构的节点. 文档是一个    文档节点 . 所有的HTML元素都是    ...

  7. 针对Openlayer3官网例子的简介

    网址:http://openlayers.org/en/latest/examples/ 如果大家想了解ol3能做什么,或者说已提供的API有什么,又闲一个个翻例子跟API累的话,就看看这个吧. 1. ...

  8. Linux入门之常用命令(2)

    (三) 链接文件 ln [-s] [源文件] [目标文件]       -s表示符号链接 没有则是硬链接 硬链接是一个独立文件 (相当于一个副本) 符号链接是一个链接文件(相当于一个快捷方式) 但是修 ...

  9. hdu 5952 连通子图

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  10. JavaWeb(四)EL表达式

    前言 前面详细的说明了什么是JSP和它的一些元素,这篇给大家介绍一下的是EL表达式. 用EL表达式,能更好的使用JSP中的各种内置对象和作用域. 楼主作为大四狗马上要出去面试了,内心很紧张!!! 一. ...