传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2516

【题解】

状压dp。

$f_{sta,i}$表示状态为sta,当前在第i层的最小花费时间。状态是个三进制表示,0代表没进过电梯;1代表在电梯里;2表示进过电梯,出来了。

然后考虑当前状态转移出去即可。复杂度$O(Cas * 3^n * nm)$,成功垫底。

据说用2个二进制可以更快(逃

# include <vector>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + ;
const int mod = 1e9+, inf = 1e9;
const int STATUS_SIZE = + ; int n, m, fir, bin[];
int f[STATUS_SIZE][], s[];
struct pa {
int t, a, b;
pa() {}
pa(int t, int a, int b) : t(t), a(a), b(b) {}
}p[]; vector<int> ps; # define abs(x) ((x) > ? (x) : -(x))
# define bit(x, i) (((x) / bin[i]) % )
# define dist(i, j) (abs(ps[j-] - ps[i-])) inline int getid(int x) {
return lower_bound(ps.begin(), ps.end(), x) - ps.begin() + ;
} inline void gmin(int &a, int b) {
if(b < a) a = b;
} inline void sol() {
cin >> n >> fir;
ps.clear(); ps.push_back(fir);
for (int i=; i<=n; ++i) {
scanf("%d%d%d", &p[i].t, &p[i].a, &p[i].b);
ps.push_back(p[i].a);
ps.push_back(p[i].b);
}
sort(ps.begin(), ps.end());
ps.erase(unique(ps.begin(), ps.end()), ps.end());
for (int i=; i<=n; ++i) {
p[i].a = getid(p[i].a);
p[i].b = getid(p[i].b);
}
fir = getid(fir); m = ps.size();
for (int sta=; sta<bin[n]; ++sta) for (int i=; i<=m; ++i) f[sta][i] = inf;
for (int i=; i<=m; ++i) f[][i] = dist(i, fir);
for (int sta=; sta<bin[n]; ++sta) {
for (int i=; i<=m; ++i) {
for (int j=; j<=n; ++j) {
if(bit(sta, j-) == ) gmin(f[sta+bin[j-]][p[j].b], max(f[sta][i] + dist(p[j].b, i), p[j].t));
else if(bit(sta, j-) == ) gmin(f[sta+bin[j-]][p[j].a], max(f[sta][i] + dist(p[j].a, i), p[j].t));
}
}
}
int ans = inf;
for (int i=; i<=m; ++i) gmin(ans, f[bin[n]-][i]);
cout << ans << endl;
} int main() {
bin[] = ; for (int i=; i<=; ++i) bin[i] = bin[i-]*;
int T; cin >> T;
while(T--) sol();
return ;
}

 

bzoj2516 电梯的更多相关文章

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

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

  2. 浮动【电梯】或【回到顶部】小插件:iElevator.js

    iElevator.js 是一个jquery小插件,使用简单,兼容IE6,支持UMD和3种配置方式,比锚点更灵活. Default Options _defaults = { floors: null ...

  3. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] --11061188刘强

    结对编程总结 队员:刘强(11061188) 林谋武(11061169) 结对编程: 结对编程的优点: 1.  两个人合作,相比于一个人自己奋斗而言,更能激发自己的潜能:我们在合作过程中,互相学习,互 ...

  4. Pair Project:电梯控制程序

    12061160刘垚鹏 & 12061166宋天舒 1.1结对编程的优缺点结对编程相对于个人编程有很多优点.首先,督促作用,在讨论过程中能够很快投入工作,为了不耽误对方时间,我们会尽快完成各自 ...

  5. luogu[1135]奇怪的电梯

    题目描述 呵呵,有一天我做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都可以停电梯,而且第i层楼(1<=i<=N)上有一个数字Ki(0<=Ki<=N).电梯只有四个按钮:开 ...

  6. 关于软件工程结对编程作业 PairProject : Elevator Scheduler(电梯调度算法的实现与测试)的总结

    1)结对编程队友 1106xxxx 张扬 1106xxxx 杨军 其中,此项目的编程实现主要由前者完成. 2)关于结对编程 结对编程的优点: 最直接的一点:在结对编程中,由于有另一个人在你身边和你配合 ...

  7. TYVJ P3522 &&洛谷 P1135 奇怪的电梯 Label:bfs

    题目描述 呵呵,有一天我做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都可以停电梯,而且第i层楼(1<=i<=N)上有一个数字Ki(0<=Ki<=N).电梯只有四个按钮:开 ...

  8. 【软件工程】电梯调度的初步实现 李亚文&&郭莉莉

    一.开门见山,代码粘 using System; using System.Collections.Generic; using System.Data; using System.Drawing; ...

  9. 【软件工程】电梯调度程序需求分析 李亚文&&郭莉莉

    2014年3月4日(14:00-16:00) 为了进一步理解电梯工作的原理,我们特地到石家庄铁道大学春晖楼坐了电梯:春晖楼东办共有电梯两部,最高楼层为11层,最低楼层为-1,两电梯可共同使用.结合调查 ...

随机推荐

  1. Internet Secure

    key Secret key(密钥):ues the same key to Encryption and decryption(symmetric-key)对称加密,需要绝对安全的空间来传递key ...

  2. iOS开发UIColor,CGColor,CIColor三者的区别和联系

    最近看了看CoreGraphics的东西,看到关于CGColor的东西,于是就想着顺便看看UIColor,CIColor,弄清楚它们之间的区别和联系.下面我们分别看看它们三个的概念: 一.UIColo ...

  3. ES6之 =>箭头函数

    原文,请点此链接http://www.cnblogs.com/allenxieyusheng/p/5784728.html 1. 第一个函数 ()=>1 解析:其实这是一个匿名函数直接执行 (f ...

  4. 异常--try..catch

    class Program { static void Main(string[] args) { try { object obj = null; int N = (int)obj; } catch ...

  5. try-with-resources语句

    try-with-resources语句是一种声明了一种或多种资源的try语句.资源是指在程序用完了之后必须要关闭的对象.try-with-resources语句保证了每个声明了的资源在语句结束的时候 ...

  6. 初入py

    1.下载工具sublime 我的网盘下载地址:https://pan.baidu.com/s/18-U1ZSg_zHoSAqUuvXj_PQ 直接解压即可 2.配置py27 在新建的文件里面编辑并保存 ...

  7. binlog2sql数据恢复

    牛叉的工具有好几个,包括MyFlash.binlog2Sql.mysqlbinlog_flashback,还有一些收费的等等,各有优劣,具体使用可自行百度 1.安装binlog2sql shell&g ...

  8. Python 源码剖析(四)【LIST对象】

    四.LIST对象 1.PyListObject对象 2.PyListObject的创建与维护 3.PyListObject 对象缓冲池 4.Hack PyListObject 1.PyListObje ...

  9. hdu 3191 How Many Paths Are There (次短路径数)

    How Many Paths Are There Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  10. Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)

    题意: 每个人有两个积分CC和TF 第i个人能战胜第j个人的条件满足下面两个条件中的一个即可 1.CCi > CCj 或 TFi > TFj 2.i能战胜k,k能战胜j. 题解: 先按CC ...