poj 2336 Ferry Loading II ( 【贪心】 )
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3704 | Accepted: 1884 |
Description
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
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
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int et[1500]; int main()
{
int n, t, m;
int caset;
scanf("%d", &caset );
int i, j;
while(caset--)
{
scanf("%d %d %d", &n, &t, &m);
for(i=1; i<=m; i++)
{
scanf("%d", &et[i] );
} //最早到达对岸的时间,取决于最后一辆车的被运送时间
//最优解是最后一辆车能够被尽早的运走 int dd, ff;
dd=m % n;
ff=m / n;
int ans=0, cnt=0;
if(dd!=0){
ans = et[dd];
ans = ans+t*2;
cnt++;
}
for(i=dd+n; i<=m; )
{
if( ans< et[i])
ans=et[i];
ans = ans+2*t;
i=i+n;
cnt++;
}
printf("%d %d\n", ans-t, cnt++ ); }
return 0;
}
poj 2336 Ferry Loading II ( 【贪心】 )的更多相关文章
- TOJ 2419: Ferry Loading II
2419: Ferry Loading II Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Subm ...
- POJ-2336 Ferry Loading II(简单DP)
Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3763 Accepted: 1919 Desc ...
- poj-2336 Ferry Loading II(dp)
题目链接: Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3946 Accepted: ...
- POJ 2609 Ferry Loading(双塔DP)
Ferry Loading Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1807 Accepted: 509 Sp ...
- Ferry Loading II_贪心
Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...
- POJ 2609 Ferry Loading
双塔DP+输出路径. 由于内存限制,DP只能开滚动数组来记录. 我的写法比较渣,但是POJ能AC,但是ZOJ依旧MLE,更加奇怪的是Uva上无论怎么改都是WA,其他人POJ过的交到Uva也是WA. # ...
- [POJ2336]Ferry Loading II
题目描述 Description Before bridges were common, ferries were used to transport cars across rivers. Rive ...
- Ferry Loading III[HDU1146]
Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- AtCoder - agc043_a 和 POJ - 2336 dp
题意: 给你一个n行m列由'#'和'.'构成的矩阵,你需要从(1,1)点走到(n,m)点,你每次只能向右或者向下走,且只能走'.'的位置. 你可以执行操作改变矩阵: 你可以选取两个点,r0,c0;r1 ...
随机推荐
- nginx的优点
Linux.MySQL.PHP这些框架的优点之前已经介绍过,LNMP和LAMP不同的一点就是Web服务器Nginx,那么Nginx相比Apache有什么优点呢? Nginx是一个小巧而高效的Linux ...
- apue学习笔记(第七章 进程环境)
本章将了解进程的环境. main函数 C程序总是从main函数开始执行,main函数的原型是: int main(int argc,char *argv[]); 其中,argc是命令行参数的数目,ar ...
- cocos2d-x-lua基础系列教程五(lua单例)
lua-单例 function newAccount(initlizedBanlance) local self = {balance = initlizedBanlance} local show ...
- iPhone换电池是原装电池好还是换第三方大容量电池好?
转:https://www.xianjichina.com/news/details_60791.html 最近这段时间苹果降速门事件持续发酵,闹得满城风雨.尽管苹果公司两次致歉,很多果粉都去更换电池 ...
- 用Putty连接Linux
随着linux应用的普及,linux管理越来越依赖远程管理.在各种telnet类工具中,putty是其中最出色的一个. 一.Putty简介 Putty是一个免费小巧的Win32平台下的teln ...
- ORACLE物化视图具体解释
一.物化的一般使用方法物化视图是一种特殊的物理表,"物化"(Materialized)视图是相对普通视图而言的.普通视图是虚拟表.应用的局限性大,不论什么对视图的查询.oracle ...
- 设计一个线程安全的单例(Singleton)模式
在设计单例模式的时候.尽管非常easy设计出符合单例模式原则的类类型,可是考虑到垃圾回收机制以及线程安全性.须要我们思考的很多其它.有些设计尽管能够勉强满足项目要求,可是在进行多线程设计的时候.不考虑 ...
- Paxos算法学习
早在1990年,Leslie Lamport(即 LaTeX 中的"La",微软研究院科学家,获得2013年图灵奖)向ACM Transactions on Computer Sy ...
- charles 4.x 破解版安装 以及使用
下载地址 https://pan.baidu.com/s/1dFvYM7B 破解方法 未破解的情况下,每30分钟会弹出一个提示,然后关闭软件 将压缩包内的 charles.jar 复制到安装目录下,替 ...
- WPF converter(包含传递复杂参数)
单值转换器 将单一值转换为特定类型的值,以日期转换为例如下: 1.定制DateConverter类,其中当值从绑定源传播给绑定目标时,调用方法Convert. 1 public class DateC ...