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. OC——多态

    书接上文,上文提到继承一个很大用途的是为了更好的实现多态,现在我们就来看看OC的多态. 多态:顾名思义就是好多种状态,以前学C#时候印象最深刻的例子是好多个类共同实现同一个接口,然后把这些类的对象都装 ...

  2. Flex布局介绍

    Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性 任何一个容器都可以指定为 Flex 布局. .box{ display: -web ...

  3. TCP/IP(三)数据链路层~2

    一.局域网 1.1.局域网和以太网的区别和联系 局域网:前面已经介绍了,其实就是学校里面.各个大的公司里,自己组件的一个小型网络,这种就属于局域网. 以太网:以太网(Ethernet)指的是由Xero ...

  4. java学习——java按值传递和按址传递

    先复制一个面试/笔试的题: 当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递? 答案: 是值传递.Java语言的方法调用只支持参 ...

  5. Nim or not Nim? hdu3032 SG值打表找规律

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. 规划自己的生活,从使用GTD时间管理法开始

    前言 为了不再浪费时间,不在茫然度过每一天,我为自己应用了GTD时间管理法,之前并不知道这种方法,实际和我自己定制的也差不太多,下面说说这个方法.   一.GTD时间管理 时间管理法有很多,而GTD( ...

  7. 富文本编辑器CKEditor的使用

    由于最近在架构一个pc端b/s结构的项目,项目中有个论坛模块,当用户发帖时,需要用到富文本编辑器,考虑了一下,决定使用CKEditor富文本编辑器,虽然现在问世的富文本编辑器很丰富,比如还有百度的UE ...

  8. python读取命令行参数的方法

    1.sys模块 需要模块:sys参数个数:len(sys.argv)脚本名:    sys.argv[0]参数1:     sys.argv[1]参数2:     sys.argv[2] test.p ...

  9. 玩转INotifyPropertyChanged和ObservableCollection

    转载:   http://www.cnblogs.com/Jax/archive/2009/10/13/1582128.html 本文的代码都是基于WPF的,对于Silverlight,这些技术也同样 ...

  10. JavaScript前端和Java后端的AES加密和解密

    在实际开发项目中,有些数据在前后端的传输过程中需要进行加密,那就需要保证前端和后端的加解密需要统一.这里给大家简单演示AES在JavaScript前端和Java后端是如何实现加密和解密的. 直接上代码 ...