poj-2336 Ferry Loading II(dp)

题目链接:

Ferry Loading II

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3946 Accepted: 1985

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. 

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

题意:

给m辆车的到达岸边的时间,现在给你一个轮渡能运车的数量,和单程的时间,现在问把这些车运过去的最短时间是多少,在这个时间中的 最少运送次数是多少?

思路:

dp[i]表示运送前i个要用的时间,num[i]表示在dp[i]的时间内的最少次数;相邻的车在一块运,转移方程看代码吧;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map>
 
using namespace std;
 
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
 
typedef  long long LL;
 
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}
 
const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=2e3+14;
const double eps=1e-12;

int a[maxn],dp[maxn],num[maxn];

int main()
{
    int T;
    read(T);
    while(T--)
    {
        int n,m,t;
        read(n);read(t);read(m);
        For(i,1,m)read(a[i]);
        For(i,1,m)dp[i]=inf,num[i]=0;
        dp[0]=0;
        num[0]=0;
        For(i,1,m)
        {
            for(int j=max(0,i-n);j<i;j++)
            {
                if(j==0){dp[i]=a[i]+t,num[i]=1;continue;}
                if(dp[i]>max(dp[j]+t,a[i])+t)dp[i]=max(dp[j]+t,a[i])+t,num[i]=num[j]+1;
                else if(dp[i]==max(dp[j]+t,a[i])+t)num[i]=min(num[i],num[j]+1);
            }
        }
        cout<<dp[m]<<" "<<num[m]<<"\n";
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5754980.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
社会发展日新月异,用计算机应用实现数据管理功能已经算是很完善的了,但是随着移动互联网的到来,处理信息不再受制于地理位置的限制,处理信息及时高效,备受人们的喜爱。所以各大互联网厂商都瞄准移动互联网这个潮流进行各大布局,经过多年的大浪淘沙,各种移动操作系统的不断面世,而目前市场占有率最高的就是微信小程序,本次开发一套新冠肺炎服务预约微信小程序有管理员,医,用户三个角色。管理员和医都可以在后台网页登录,管理员功能有个人中心,医管理,用户管理,防疫措施管理,疫苗信息管理,核酸检测管理,疫苗预约管理,核酸预约管理,接种信息管理,检测结果管理,系统管理。医可以注册登录,管理疫苗信息和核酸检测信息,审核疫苗预约信息和核酸预约信息,查看接种信息和检测结果。用户可以在微信小程序注册登录,可以预约疫苗和核酸检查,可以查看到接种信息和检测结果。新冠肺炎服务预约微信小程序服务端用Java开发的网站后台,接收并且处理微信小程序端传入的json数据,数据库用到了MySQL数据库作为数据的存储。这样就让用户用着方便快捷,都通过同一个后台进行业务处理,而后台又可以根据并发量做好部署,用硬件和软件进行协作,满足于数据的交互式处理,让用户的数据存储更安全,得到数据更方便。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值