线段树+SPFA最短路可以过。或者DP也能过。
需要注意的是xl的范围是错的,测试用例中xl可能为0,他妈的,因为这个一直莫名其妙的wa。
1. spfa建图增加一倍的点即可(讨论左端点和右端点)。

 /* 2155 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct {
int v, w, nxt;
} edge_t; typedef struct node_t {
int xl, xr, y; node_t() {}
node_t(int xl, int xr, int y):
xl(xl), xr(xr), y(y) {} friend bool operator <(const node_t& a, const node_t& b) {
return a.y < b.y;
} } node_t; const int maxv = ;
const int maxe = maxv * ;
const int INF = 0x3f3f3f3f;
int n, x, y, mx, T;
edge_t E[maxe];
int head[maxv<<];
bool visit[maxv<<];
int dis[maxv<<];
node_t nd[maxv];
int l = , m;
int start, End;
int ID[maxv<<];
int L, R, id; void init() {
l = ;
m = ;
memset(head, -, sizeof(head));
} void addEdge(int u, int v, int w) {
E[l].v = v;
E[l].w = w;
E[l].nxt = head[u];
head[u] = l++;
} void Build(int l, int r, int rt) {
ID[rt] = ;
if (l == r)
return ; int mid = (l + r) >> ;
Build(lson);
Build(rson);
} inline void PushDown(int rt) {
if (ID[rt]) {
ID[rt<<] = ID[rt<<|] = ID[rt];
ID[rt] = ;
}
} void Update(int l, int r, int rt) {
if (L<=l && R>=r) {
ID[rt] = id;
return ;
} PushDown(rt);
int mid = (l + r) >> ; if (R <= mid) {
Update(lson);
} else if (L > mid) {
Update(rson);
} else {
Update(lson);
Update(rson);
}
} int Query(int k, int l, int r, int rt) {
if (l == r)
return ID[rt]; PushDown(rt);
int mid = (l + r) >> ; if (k <= mid)
return Query(k, lson);
else
return Query(k, rson);
} int spfa() {
queue<int> Q;
int u, v, k; memset(visit, false, sizeof(visit));
memset(dis, INF, sizeof(dis));
dis[start] = ;
visit[start] = true;
Q.push(start); while (!Q.empty()) {
u = Q.front();
Q.pop();
visit[u] = false;
for (k=head[u]; k!=-; k=E[k].nxt) {
v = E[k].v;
if (dis[u]+E[k].w < dis[v]) {
dis[v] = dis[u] + E[k].w;
if (!visit[v]) {
visit[v] = true;
Q.push(v);
}
}
}
} return dis[End];
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t;
int lid, rid;
int tmp, w; scanf("%d", &t);
rep(tt, , t+) {
scanf("%d %d %d %d %d", &n, &x, &y, &mx, &T);
++x;
init();
rep(i, , n) {
scanf("%d %d %d", &nd[m].xl, &nd[m].xr, &nd[m].y);
++nd[m].xl;
++nd[m].xr;
if (nd[m].y < y)
++m;
} nd[m].xl = x;
nd[m].xr = x;
nd[m].y = y;
++m;
nd[m].xl = ;
nd[m].xr = ;
nd[m].y = ;
sort(nd+, nd++m);
End = ;
start = m;
memset(ID, , sizeof(ID)); L = nd[].xl;
R = nd[].xr;
id = ;
Update(, , );
rep(i, , m+) { // handle left
L = nd[i].xl;
lid = Query(L, , , );
tmp = nd[i].y - nd[lid].y;
if (tmp <= mx) {
if (lid == End) {
w = tmp;
addEdge(i, lid, w);
} else {
// to left of lid
w = tmp + nd[i].xl - nd[lid].xl;
addEdge(i, lid, w); // to right of lid
w = tmp + nd[lid].xr - nd[i].xl;
addEdge(i, lid+m, w);
}
} // handle right
if (i != m) {
R = nd[i].xr;
rid = Query(R, , , );
tmp = nd[i].y - nd[rid].y;
if (tmp <= mx) {
if (rid == End) {
w = tmp;
addEdge(i+m, rid, w);
} else {
// to left of rid
w = tmp + nd[i].xr - nd[rid].xl;
addEdge(i+m, rid, w); // to right of rid
w = tmp + nd[rid].xr - nd[i].xr;
addEdge(i+m, rid+m, w);
}
}
} L = nd[i].xl;
R = nd[i].xr;
id = i; Update(, , );
} tmp = spfa();
if (tmp==INF || tmp>T)
puts("YES");
else
puts("NO");
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

2. DP, 二维DP,没什么好说的。

 /* 2155 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct node_t {
int l, r, h; node_t() {}
node_t(int l, int r, int h):
l(l), r(r), h(h) {} friend bool operator< (const node_t& a, const node_t& b) {
return a.h > b.h;
} } node_t; const int maxn = ;
const int INF = 0x3f3f3f3f;
node_t nd[maxn];
int dp[maxn][];
int n, x, y, mx, T; void solve() {
bool fl, fr;
int tmp; memset(dp, INF, sizeof(dp));
dp[][] = dp[][] = ;
rep(i, , n) {
#ifndef ONLINE_JUDGE
printf("l = %d, r = %d, [0] = %d, [1] = %d\n", nd[i].l, nd[i].r, dp[i][], dp[i][]);
#endif
fl = fr = true;
rep(j, i+, n+) {
tmp = nd[i].h - nd[j].h;
if (tmp > mx)
break;
if (fl && nd[j].l<=nd[i].l && nd[i].l<=nd[j].r) {
fl = false;
if (j == n) {
dp[j][] = min(dp[j][], dp[i][]+tmp);
dp[j][] = min(dp[j][], dp[i][]+tmp);
} else {
dp[j][] = min(dp[j][], dp[i][]+tmp+nd[i].l-nd[j].l);
dp[j][] = min(dp[j][], dp[i][]+tmp+nd[j].r-nd[i].l);
}
}
if (fr && nd[j].l<=nd[i].r && nd[i].r<=nd[j].r) {
fr = false;
if (j == n) {
dp[j][] = min(dp[j][], dp[i][]+tmp);
dp[j][] = min(dp[j][], dp[i][]+tmp);
} else {
dp[j][] = min(dp[j][], dp[i][]+tmp+nd[i].r-nd[j].l);
dp[j][] = min(dp[j][], dp[i][]+tmp+nd[j].r-nd[i].r);
}
}
}
} if (dp[n][]<=T || dp[n][]<=T)
puts("NO");
else
puts("YES");
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t; scanf("%d", &t);
while (t--) {
scanf("%d %d %d %d %d", &n, &x, &y, &mx, &T);
nd[].l = nd[].r = x;
nd[].h = y;
rep(i, , n+)
scanf("%d %d %d", &nd[i].l, &nd[i].r, &nd[i].h);
sort(nd, nd+n);
++n;
nd[n].l = ;
nd[n].r = ;
nd[n].h = ;
solve();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】2155 小黑的镇魂曲的更多相关文章

  1. hdu 2155 小黑的镇魂曲(dp) 2008信息工程学院集训队——选拔赛

    感觉蛮坑的一道题. 题意很像一个叫“是男人下100层”的游戏.不过多了个时间限制,要求在限定时间内从某一点下落到地面.还多了个最大下落高度,一次最多下落这么高,要不然会摔死. 一开始想dp的,然后想了 ...

  2. hdu2155 小黑的镇魂曲(dp)

    题意:                             小黑的镇魂曲 Problem Description 这个事情发生在某一天,当小黑和SSJ正在约会的时候,邪恶的Guner抓走了SSJ, ...

  3. 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)

    题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  9. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

随机推荐

  1. asp:保留两位小数:

    <%=Formatnumber(-6665.8999,3,-1,-1,0)%>(6665.900)一个例子用到了函数Formatnumber()的所有参数:第一个参数(-6665.8999 ...

  2. OpenJudge/Poj 2013 Symmetric Order

    1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...

  3. Ubuntu 14.04为浏览器添加Flash插件

    在刚安装好到Ubuntu操作系统中默认是没有flash支持到,因此,当我们使用浏览器查看很多视频网页到时候,会导致网页上到视频无法播放.然而,这个问题我们也不能够通过“软件中心”来解决,这时候需要我们 ...

  4. Mysql表操作

    查看表结构: 可以使用describe或show create table语句查看表的结构: describe表名; Show create table 表名; 修改表名: Alter table 旧 ...

  5. Web前端新人笔记之文本属性

    前一段时间因工作时间减缓了更新笔记的时间.我也不知道有没有会观看并且能不能帮到一些初学者,这只是我的一些小随笔而已.当然我也希望的的每一篇随笔都可以帮到更多的想要学习前端开发的初学者们,更希望你们也可 ...

  6. SQL技巧之排名统计

    有一道SQL笔试题是这样子的: 已知表信息如下: Department(depID, depName),depID 系编号,DepName系名 Student(stuID, name, depID)  ...

  7. 【4】创建一个自己的Bootstrap模板

    什么也不说了,直接贴上代码吧,哈哈 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta ch ...

  8. python27读书笔记0.2

    # -*- coding:utf-8 -*- ##s.partition(d)##Searches string s for the first occurrence of some delimite ...

  9. hdu 5646 DZY Loves Partition 二分+数学分析+递推

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5646 题意:将n分成k个正整数之和,要求k个数全部相同:并且这k个数的乘积最大为多少?结果mod 1e^9 ...

  10. 【Git 】$ ./gradlew idea 构建一个idea的项目

    Welcome to Git (version 1.9.5-preview20150319) Run 'git help git' to display the help index.Run 'git ...