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. cubieboard变身AP 分类: ubuntu cubieboard 2014-11-25 14:04 277人阅读 评论(0) 收藏

    加载bcmdhd模块:# modprobe bcmdhd 如果你希望开启 AP 模式,那么:# modprobe bcmdhd op_mode=2 在/etc/modules文件内添加bcmdhd o ...

  2. Spark1.0.0 监测方法

          Spark1.0.0能够通过下面几种方式来对Spark应用程序进行监控: Spark应用程序的WebUI或者Spark Standalone的集群监控 指标,然后通过支持指标收集的集群监控 ...

  3. qt 学习之路 :QML 语法

    前面我们已经见识过 QML 文档.一个 QML 文档分为 import 和对象声明两部分.如果你要使用 Qt Quick,就需要 import QtQuick 2.QML 是一种声明语言,用于描述程序 ...

  4. ARCGIS二维三维平移

    private void glZoomPan() { ESRI.ArcGIS.SystemUI.ICommand com = new ControlsGlobePanTool(); com.OnCre ...

  5. 解决error:could not open ...jvm.cfg

    出现error:could not open '...jvm.cfg'大多是以前安装jdk或者jre的时候在注册表里注册过,现在安装的文件夹不在或者换了名字,有很多解决方法,最简单的一招是删除java ...

  6. Android开发报错系列(一),java.lang.NullPointerException,at android.widget.ListView.setupChild

    问题描述:运行代码是报空指针错误,java.lang.NullPointerException,at Android.widget.ListView.setupChild 问题定位:listview控 ...

  7. Unity3D 5.0简单的射线检测实现跳跃功能

    这里是一个简单的跳跃,5.0和其他版本貌似不一样,并且,再起跳功能做的不完全. 不过一个基本的思路在这里. 1.首先,射线检测,这里是利用一个空对象,放到主角对象的下面 2.然后调节射线的位置,在主角 ...

  8. HTML5 <Audio>标签API整理(一)

    简单实例: <audio id="myAudio"></audio> <script> var myAudio = document.getEl ...

  9. Wireshark提示没有一个可以抓包的接口

    这是由于win下默认NPF服务是关闭的,需要以管理员的身份开启这个服务 Windows上安装wireshark时,会遇到NPF驱动无法启动的情况,一般如果采用管理员的方式就可以正常启动,或者是将NPF ...

  10. SQL SERVER 中PatIndex的用法个人理解

    一般用法:PatIndex('%AAA%',‘BBBBBBBB’) 上句的意思是查找AAA在BBBBBBBB中的位置,从1开始计算,如果没有的话则返回0 其中%AAA%的用法和 SQL语句中like的 ...