诡异的电梯【Ⅰ】
时间限制:1000 ms | 内存限制:65535 KB
难度:3

描述
新的宿舍楼有 N(1≤N≤100000) 层 and M(1≤M≤100000)个学生. 在新的宿舍楼里, 为了节约学生的时间也为了鼓励学生锻炼身体, 所以规定该宿舍楼里的电梯在相邻的两层之间是不会连续停下(即,如果在第2层停下就不能在第3层停下。).所以,如果有学生在相邻的两层之间要停下, 则其中的一部分学生必须选择走楼梯来代替。规定:一个人走下一层楼梯的花费为A,走上一层楼梯的花费为B。(1≤A,B≤100)现在请你设计一个算法来计算出所有学生走楼梯花费的最小费用总和。 所有的学生一开始都在第一层,电梯不能往下走,在第二层的时候电梯可以停止。

输入
输入有几组数据T。T(1≤T≤10)
每组数据有N (1≤N≤100000),M(1≤M≤100000),A,B(1≤A,B≤100)。
接下来有M个数字表示每个学生想要停的楼层。

输出
输出看样例。

样例输入
1
3 2 1 1
2 3
样例输出
Case 1: 1

提示
原题:
The new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise, the elevator in dormitory will not stop in adjacent floor. So if there are people want to get off the elevator in adjacent floor, one of them must walk one stair instead. Suppose a people go down 1 floor costs A energy, go up 1 floor costs B energy(1≤A,B≤100). Please arrange where the elevator stop to minimize the total cost of student's walking cost.All students and elevator are at floor 1 initially, and the elevator can not godown and can stop at floor 2.

OUTPUT:
Output case number first, then the answer, the minimum of the total cost of student's walking cost.
来源
翻译【2014湘潭邀请赛】

上传者
ACM_钟诗俊

解题:动态规划。dp[i]表示在i层停下,现在假设在i层停下,那么上一次停的曾可以是i-2或者是i-3

假设是i-2。那么去i-1的人可以做到i再下一层,或者直接在i-2的时候走上一层,min(up,down)*a[i-1]

假设在i-3层停的,那么情况是,i-2的人可以做到i下去两层,或者从i-3走上一层,同理i-1的人。。。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int a[maxn],dp[maxn],up,down,n,m;
int main() {
int t,tmp,cs = ;
scanf("%d",&t);
while(t--){
scanf("%d %d %d %d",&n,&m,&down,&up);
memset(dp,0x3f,sizeof(dp));
memset(a,,sizeof(a));
for(int i = ; i < m; ++i){
scanf("%d",&tmp);
a[tmp]++;
}
dp[] = dp[] = dp[] = ;
for(int i = ; i <= n; ++i){
dp[i] = min(dp[i],dp[i-]+min(up,down)*a[i-]);
int x = min(a[i-]*down,a[i-]*up*);
int y = min(a[i-]*up,a[i-]*down*);
dp[i] = min(dp[i],dp[i-]+x+y);
}
printf("Case %d: %d\n",cs++,dp[n]);
}
return ;
}

NYIST 1070 诡异的电梯【Ⅰ】的更多相关文章

  1. NYOJ 诡异的电梯 && nyoj 1204 魔法少女

    诡异的电梯[Ⅰ] 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 新的宿舍楼有 N(1≤N≤100000) 层 and M(1≤M≤100000)个学生. 在新的宿舍楼里 ...

  2. NYOJ-1070诡异的电梯【Ⅰ】

    这道题是个dp,主要考虑两种情况,刚开始我把状态转移方程写成了dp[i] = min(dp[i-1] + a, dp[i + 1] +b); 后来想想当推到dp[i]的时候,那个dp[i + 1]还没 ...

  3. XTUOJ 1206 Dormitory's Elevator

    Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dorm ...

  4. 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    软件工程  ---   Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] 说明结对编程的优点和缺点. 结对编程的优点如下: 在独立设计.实现代码的过程中不 ...

  5. 你电梯没了—OO第二单元作业思考

    写在前面 这三次电梯调度作业,主要是学习多线程并行操作,对于各个线程的时间轴的把握,互相的配合与影响,通过使用锁来解决访问冲突等方面. 个人在学会Thread相关操作之外,写出来一些奇怪结构的诡异操作 ...

  6. 你还可以再诡异点吗——SQL日志文件不断增长

    前言 今天算是遇到了一个罕见的案例. SQL日志文件不断增长的各种实例不用多说,园子里有很多牛人有过介绍,如果我再阐述这些陈谷子芝麻,想必已会被无数次吐槽. 但这次我碰到的问题确实比较诡异,其解决方式 ...

  7. Delphi编程时候诡异地出现ORA-00937错误,记录解决它的思路和方法

    首先需要说明,这个问题的出现需要几个前提:使用微软的Oracle驱动(使用Oracle自己的驱动不会出现这个问题).使用绑定变量法,使用Format等方式拼接SQL也不会出现这个问题,还有一些诡异的规 ...

  8. 诡异的localhost无法连接

    上午试了localhost发现提示无法连接,ping了下localhost,能够ping通. 重启了Apache,还是无法解决. 试着停止了Apache服务,然后再连接localhost,发现浏览器提 ...

  9. 自己动手C#模拟电梯的运行V1.0

    电梯调度有很多种模式,参见http://www.cnblogs.com/jianyungsun/archive/2011/03/16/1986439.html 1.1先来先服务算法(FCFS) 先来先 ...

随机推荐

  1. ActiveMQ 发送和接收消息

    一.添加 jar 包 <dependency> <groupId>org.apache.activemq</groupId> <artifactId>a ...

  2. ZOJ 3885 The Exchange of Items

    The Exchange of Items Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. O ...

  3. nodejs-EventEmitter

    addListener(event, listener)为指定事件添加一个监听器到监听器数组的尾部. on(event, listener)为指定事件注册一个监听器,接受一个字符串 event 和一个 ...

  4. WebApi传参总动员(一)

    目前自己的工作和WebApi相关,免不了传入.接收参数.以前的老办法是从请求流中获取json,再反序列化,这中间有2个不能控制的地方,一个是流,一个是反序列化,都需要try,总感觉非常的不爽.因此对W ...

  5. Linux Unix shell 编程指南学习笔记(第三部分)

    第十三章  登陆环境 登陆系统时.输入username和password后.假设验证通过.则进入登录环境. 登录过程 文件/etc/passwd $HOME.profile 定制$HOME.profi ...

  6. HDU 2732 Leapin&#39; Lizards(拆点+最大流)

    HDU 2732 Leapin' Lizards 题目链接 题意:有一些蜥蜴在一个迷宫里面,有一个跳跃力表示能跳到多远的柱子,然后每根柱子最多被跳一定次数,求这些蜥蜴还有多少是不管怎样都逃不出来的. ...

  7. 从HTTP 2.0想到的关于传输层协议的一些事

    0.HTTP协议的历史 我也不知道... 1.关于HTTP 2.0 收到了订阅的邮件,头版是说HTTP 2.0的内容,我本人不是非常关注HTTP这一块儿.可是闲得无聊时也会瞟两眼的.HTTP 2.0的 ...

  8. linux下使用convert命令修改图片分辨率【转】

    本文转载自:http://blog.csdn.net/mybelief321/article/details/9969949 Convert的resize子命令应该是在ImageMagick中使用较多 ...

  9. dns tunnel工具地址

  10. SQL的优化技巧

    一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好 ...