uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1381

题意:题意:一条船能够一次最多渡n辆车过河,过河用t min,回来又要用t min。m辆车按照一定的计划到达岸边。现在要求最少

用多少时间就所有的船渡过河,以及用了最少多少次将所有。

题解:用贪心思想,最早运到对岸的时间,取决于最后来的一辆车的被运送时间,因此最优解就是最后一辆车能够最早被运送。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int cas,n,t,m,ll,train_timess,times;
int map[];
int main(){
scanf("%d",&cas);
while(cas--){
scanf("%d%d%d",&n,&t,&m);
for(int i=;i<=m;i++)
scanf("%d",&map[i]);
ll=m%n;train_timess=;times=;
if(ll==){
train_timess=m/n;
for(int i=n;i<m;i+=n){
times=max(map[n],times)+*t;
}
times=max(map[m],times)+t;
}
else{train_timess=m/n+;
times=map[ll]+*t;
for(int i=ll+n;i<m;i+=n){
times=max(times,map[i])+*t;
}
times=max(map[m],times)+t;
}
printf("%d %d\n",times,train_timess); }
}

Ferry Loading||的更多相关文章

  1. Ferry Loading III[HDU1146]

    Ferry Loading IIITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. POJ-2336 Ferry Loading II(简单DP)

    Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3763 Accepted: 1919 Desc ...

  3. POJ 2609 Ferry Loading(双塔DP)

    Ferry Loading Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1807   Accepted: 509   Sp ...

  4. poj 2336 Ferry Loading II ( 【贪心】 )

    Ferry Loading II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3704   Accepted: 1884 ...

  5. poj-2336 Ferry Loading II(dp)

    题目链接: Ferry Loading II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3946   Accepted: ...

  6. TOJ 2419: Ferry Loading II

    2419: Ferry Loading II  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Subm ...

  7. Ferry Loading II_贪心

    Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...

  8. [POJ2336]Ferry Loading II

    题目描述 Description Before bridges were common, ferries were used to transport cars across rivers. Rive ...

  9. 【HDOJ】1406 Ferry Loading III

    模拟,注意需要比较队头与当前时间的大小关系. #include <cstdio> #include <cstring> #include <cstdlib> #de ...

随机推荐

  1. CSS——(1)基础

    CSS(Cascading Style Sheets)层叠样式表 含义 一种计算机语言: 能够实现网页与内容分离: 用来表现文件样式,如HTML或XML: 比較 div与css 假设说div是容器的话 ...

  2. JS浮点类型计算

    /* ---------------- JS浮点数运算重置 ---------------- */ //加法函数 //调用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精确结 ...

  3. spring mvc DispatcherServlet详解之拾忆工具类utils

    DispatcherServlet的静态初始化 /** * Name of the class path resource (relative to the DispatcherServlet cla ...

  4. IOS的工程目录结构和生命周期

    IOS的工程目录结构和生命周期 ·simple table文件夹:工程相关源代码和配置文件 BIDAppDelegate :    委托的声明和实现 BIDViewController:    视图控 ...

  5. Java设计模式03:常用设计模式之单例模式(创建型模式)

    1.  Java之单例模式(Singleton Pattern ) 单例模式是一种常见的设计模式,单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类只能有一个实 ...

  6. Python 记录(一)

    一开始没发现3.5与2.x版本的区别,导致浪费了很多时间在导包等问题上: 如: Pyhton2中的urllib2工具包,在Python3中分拆成了urllib.request和urllib.error ...

  7. [转]C#中yield用法

    yield 关键字向编译器指示它所在的方法是迭代器块.编译器生成一个类来实现迭代器块中表示的行为.在迭代器块中,yield 关键字与 return 关键字结合使用,向枚举器对象提供值.这是一个返回值, ...

  8. java读取redis的timeout异常

    http://blog.csdn.net/shuaiokshuai/article/details/23266091 FIFO Fist-in Fisrt-out 先进先出

  9. 利用反射把数据集合转换成List

    ---ResultSet数据集 public static List toList(ResultSet rs, Class cls) { List list = new ArrayList(); tr ...

  10. SQL数据库安装

    安装过程中经常出现失败或者提示,那么久要清楚干净所有的数据在重新安装,步骤如下. SQL2008卸载 一.从控制面板卸载 1)点击计算机右下角“开始”,点击“控制面板” 2)点击“卸载程序”. 卸载与 ...