传送门: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. 用URL传参带特殊字符,特殊字符丢失

    文章:URL中编码URL特殊字符 文章:用URL传参带特殊字符,特殊字符丢失(encode) 如果url中有特殊字符,需要对url进行编码,否则特殊字符丢失,导致最终接收到的值不对.

  2. android入门 — ListView的优化

    ListView的运行效率是比较低的,因为在getView()中每次都会将整个布局重新加载一遍,当ListView快速滚动的时候就会成为性能瓶颈. 调用View中的findViewById()方法获取 ...

  3. lintcode-178-图是否是树

    178-图是否是树 给出 n 个节点,标号分别从 0 到 n - 1 并且给出一个 无向 边的列表 (给出每条边的两个顶点), 写一个函数去判断这张`无向`图是否是一棵树 注意事项 你可以假设我们不会 ...

  4. <Effective C++>读书摘要--Templates and Generic Programming<一>

    1.The initial motivation for C++ templates was straightforward: to make it possible to create type-s ...

  5. C#中堆和栈的区别?

    http://www.jb51.net/article/55306.htm http://www.cnblogs.com/JimmyZhang/archive/2008/01/31/1059383.h ...

  6. PAT 甲级 1038 Recover the Smallest Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...

  7. tweenjs缓动算法使用小实例

    这里的tweenjs不是依托于createjs的tewwnjs,而是一系列缓动算法集合.因为本身是算法,可以用在各个业务场景中,这也正是总结学习它的价值所在.tweenjs代码详情: /* * Twe ...

  8. Visual C++中对运行时库的支持

    原文地址:http://blog.csdn.net/wqvbjhc/article/details/6612099 一.什么是C运行时库 1)C运行时库就是 C run-time library,是 ...

  9. [剑指Offer] 50.数组中重复的数字

    题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...

  10. stm32f407启动文件分析

    ; Amount of memory (in bytes) allocated for Stack; Tailor this value to your application needs; < ...