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 ... 
随机推荐
- GIS可视化——热点格网图
			一.简介 原理:按照格网大小将区域进行划分,由一个矩形格网替代当前范围内的数据,由格网中心数字代替格网的权重(可以为格网中数据的数量,数据某权重的平均值.最大值.最小值等), 由格网之间颜色的不同表达 ... 
- 几种Tab的实现方法
			转载请注明出处,谢谢! 学了这久Android,今天来总结一下几种Tab的实现方法 实现方法一: ViewPage来实现 首先创建一个top.xml布局和一个bottom.xml布局,然后在主界面中通 ... 
- 微信小程序 - 对象转换成对象数组
			后端传过来的一个个对象 {1,2,3,4},{1,3,5,},{1,3,5} 我们应该转化为数组对象 [{},{},{},{}] ,最后通过wx:for遍历到页面 示例图: 
- vue.js+koa2项目实战(三)登录注册模态框
			登录注册模态框 注: [Vue warn]: Do not use built-in or reserved HTML elements as component id: diaLog 原因:diaL ... 
- JSConsole调试
			http://jsconsole.com/ https://github.com/remy/jsconsole 
- WCF TCP通信方式 通过IIS承载调试
			http://www.cnblogs.com/nikymaco/archive/2012/10/08/2715954.html IIS Express服务器只支持http/https,不支持net.t ... 
- C#按指定长度分割字符串
			C#按指定长度分割字符串 这几天学习分析声音的波形数据,接收到的是十六进制的数据,需要将数据转换成十进制再绘图,这个过程涉及到字符串的分割,正好可以促进自己对C#相关知识的学习.说到分割字符串,我 ... 
- we are experimenting with a new init system and it is fun
			http://0pointer.de/blog/projects/systemd.html Rethinking PID 1 If you are well connected or good at ... 
- 存储过程清理N天前数据
			CREATE OR REPLACE PROCEDURE APICALL_LOG_INTERFACE_CLEAN ( CLEANDAY IN Number --天数 ) AS v_cleanDay nu ... 
- Mysql或者Hive数据行变成列
			对于mysql / hive 再进行统计的时候假设须要行变成列,能够使用函数 CASE 字段a WHEN 值b THEN c [WHEN d THEN e]* [ELSE f] END 当字段a=值 ... 
