poj 2336 Ferry Loading II ( 【贪心】 )
2015-04-02 19:31
363 查看
Ferry Loading II
DescriptionBefore 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?
InputThe
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.
OutputFor
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
Sample Output
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3704 | Accepted: 1884 |
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?
InputThe
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.
OutputFor
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 贪心
- 贪心之 Ferry Loading II (POJ 2336)
- POJ 2336 Ferry Loading II (贪心或动态规划)
- poj 2336 Ferry Loading II dp
- ACM HEU OJ 1019 Ferry Loading II || POJ 2336
- POJ 2336 Ferry Loading II(运车过河的最短时间和次数)
- POJ-2336 Ferry Loading II(简单DP)
- POJ-2336 Ferry Loading II(简单DP)
- 目的地返回POJ 2336 动态规划(DP) Ferry Loading II
- POJ 2336 Ferry Loading II 动态规划
- poj-2336 Ferry Loading II(dp)
- poj 2336 Ferry Loading II
- poj 2336 ferry loadII
- 【贪心】poj2336 ferry loading II
- POJ2336 Ferry Loading II 贪心动规
- POJ 2609 Ferry Loading(双塔DP)
- POJ 3282 Ferry Loading IV(模拟)
- HEU 1020 Ferry Loading II
- POJ 2609 Ferry Loading 双塔DP
- POJ 2609 Ferry Loading 笔记