[ACM Day1]BAPC2014 D.Lift Problem

本文探讨了一个经典的电梯调度问题,目标是最小化乘客的不满情绪。通过动态规划的方法,找到最佳的电梯停靠策略,减少乘客因等待和错过楼层而产生的不满。

题目描述

On the ground floor (floor zero) of a large university building a number of students are wait- ing for a lift. Normally, the lift stops at every floor where one or more students need to get out, but that is annoying for the students who want to get out on a higher floor. Alternatively, the lift could skip some floors, but that is annoying for the students who wanted to get out on one of those floors.
Specifically, a student will be annoyed on every floor where the lift stops, if the lift has not yet reached the floor on which he or she wants to get out. If the lift skips the floor on which a student wants to get out, he or she will be annoyed on that floor and every higher floor, up to (and excluding) the floor where the lift makes its next stop and the student can finally get out to start walking back down the stairs to his or her destination.For example, if a student wants to get out on the fifth floor, while the lift stops at the second, seventh and tenth floor, the student will be annoyed on floors two, five and six. In total, this student will thus be annoyed on three floors.
Upon entering the lift, every student presses the button corresponding to the floor he or she wants to go to, even if it was already pressed by someone else. The CPU controlling the lift thus gets to know exactly how many students want to get out on every floor.
You are charged with programming the CPU to decide on which floors to stop. The goal is to minimize the total amount of lift anger: that is, the number of floors on which every student is annoyed, added together for all students.
You may ignore all the people who may (want to) enter the lift at any higher floor. The lift has to operate in such a way that every student waiting at the ground floor can reach the floor she or he wants to go to by either getting out at that floor or by walking down the stairs.

数据范围

On the first line one positive number: the number of test cases, at most 100. After that per test case:
one line with a single integer n: the number of floors of the building, excluding the ground floor.
one line with n space-separated integers s[i] for each floor i, the number of students s[i] that want to get out.
N<=1500,1<=s[i]<=1500N<=1500,1<=s[i]<=1500

题目分析

第一次打ACM,这样长的英文题面让我很难受,没有什么耐心读下去,简化一下问题就是这样的,有0N0−N个楼层,你知道每一层下去的人数,如果一个人在第ii层下,当电梯停靠在比i低的层jj且打开电梯门是,所有在i层下电梯的人都会产生一个单位愤怒值,如果到比自己预期停靠层高的人,不管停不停都会产生一个单位的愤怒值,问所有人下电梯后,一共会产生多少的愤怒值。
f[i]f[i]表示到第ii层最少产生的愤怒值

f[i]=min(f[j]+k=ji1(ik)s[k]+k=i+1ns[k])(j<i)

边界条件就是f[0]=0f[0]=0,在每次计算之前维护s[k]∑s[k]ks[k]∑k∗s[k]两个前缀和,这样可以做到O(1)O(1)转移,复杂度O(N2)O(N2)

#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
int _read(){
    char ch = getchar();
    int x = 0 , f = 1 ;
    while( !isdigit( ch ) )
           if( ch == '-' ) f = -1 , ch = getchar();
           else ch = getchar();
    while( isdigit( ch ) )
           x = (ch  - '0') + x * 10 , ch =  getchar();
    return x * f;
}
const int maxn = 2000 + 5;
int f[maxn] , s[maxn] , pre1[maxn] , pre2[maxn]; 
int main(){
//  freopen("test.out" , "w" , stdout );
    int T = _read();
    while( T-- ){
        memset( f , 0x7f , sizeof f );
        int N = _read();
        rep( i , 1 , N ) s[i] = _read();
        rep( i , 1 , N ){
            pre1[i] = pre1[i - 1] + s[i];
            pre2[i] = pre2[i - 1] + s[i] * i;
        }
        f[0] = 0;
        int t1 = 0 , t2 = 0;
        rep( i , 1 , N )
            rep( j , 0 , i - 1 ){
                t1 = t2 = 0;
                t1 = i * ( pre1[i - 1] - pre1[j] );
                t2 = pre2[i - 1] - pre2[j];
                f[i] = min( f[i] , f[j] + t1 - t2 + pre1[N] - pre1[i] );
            }
        cout << f[N] << endl;
    }
    return 0;
}
打开链接下载源码: https://pan.quark.cn/s/a4b39357ea24 QT框架是由Qt公司设计的一种跨平台C++图形用户界面应用程序开发工具包,该框架被广泛地应用于桌面电脑、移动设备以及嵌入式系统等领域。QTableView作为QT框架中的一个核心组件,其主要功能是用于展示表格形式的数据,并且常常与QAbstractItemModel或QSqlTableModel等模型类协同工作。在QTableView中嵌入自定义组件,例如按钮,能够实现更加多样化的用户交互功能。 在QT框架环境下,若想在QTableView的一列中嵌入两个按钮,我们需要掌握以下几个关键的技术要点: 1. **QTableView**:QTableView是QTableView类的一个实例,它提供了一个二维的表格视图界面,可以用来展示和编辑模型中的数据。QTableView能够显示由QAbstractItemModel子类所提供的数据,例如QStandardItemModel或QAbstractTableModel等。 2. **QTableWidgetItem**:在QTableView中,QTableWidgetItem是构成表格单元格的基本对象,它用于表示表格中每一行每一列的数据。在默认情况下,QTableView仅能展示文本信息,但通过继承QTableWidgetItem并重新绘制,我们可以实现自定义的内容,比如嵌入按钮。 3. **自定义视图项**:若要在单元格内部嵌入两个按钮,我们需要开发一个自定义的QTableWidgetItem子类,该子类中包含两个QPushButton。这个子类需要重写paintEvent()方法以绘制按钮,并且实现必要的信号和槽机制来处理按...
内容概要:本文系统研究了LLC谐振变换器的变频移相混合控制模型,并基于Simulink平台进行了完整的仿真实现。文章首先阐述了LLC谐振变换器在高频高效电源转换中的工作原理与技术优势,重点提出了一种融合变频控制与移相控制的混合调控策略,旨在拓宽输出调节范围并提升系统的动态响应能力与运行效率。通过建立精确的系统数学模型,设计了复合控制框图,并在Simulink中搭建仿真系统,全面验证了该控制策略在不同负载条件和输入电压波动下的稳定性、效率表现及软开关实现能力。仿真结果表明,所提出的混合控制方法能有效降低开关损耗,提高能量转换效率,具备良好的工程应用前景。; 适合人群:具备电力电子技术、自动控制理论基础,熟悉Simulink仿真环境,从事高频电源变换器、谐振变换器设计与优化的研究生、科研人员及电力电子领域工程技术人员。; 使用场景及目标:①用于高性能LLC谐振变换器控制系统的设计与动态性能优化;②为软开关技术在电力电子变换器中的应用提供仿真验证平台;③支撑相关课题的科研论文撰写、项目开发与创新方案验证。; 阅读建议:建议读者结合Simulink仿真模型文件进行同步操作,深入理解变频与移相控制的协调机制、控制环路设计及关键参数整定方法,重点关注软开关实现条件与系统效率优化路径,以促进理论研究向实际工程应用的转化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值