线段树+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. 中文字符集编码Unicode ,gb2312 , cp936 ,GBK,GB18030

    中文字符集编码Unicode ,gb2312 , cp936 ,GBK,GB18030 内容详见: http://www.360doc.com/content/11/1004/12/6139921_1 ...

  2. 【html】【20】高级篇--轮播图[聚焦]

    下载: http://sc.chinaz.com/jiaoben/151204445580.htm 效果: html <!doctype html> <html> <he ...

  3. 九度OJ 1348 数组中的逆序对 -- 归并排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1348 题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求 ...

  4. OpenJudg / Poj 1363 Rails

    1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...

  5. [java学习笔记]java语言基础概述之标识符&关键字&注释&常量和变量

    一.标识符 在程序中自定义的一些名称 由26个英文字母的大小写,数字,_$组成 定义合法标识符的规则: 不能以数字开头 不能使用关键字 java严格区分大小写 注意:在起名字时,为了提高阅读性,必须得 ...

  6. 实习笔记-2:sql 分组不一定要group by

    今天在公司写代码的时候,遇到一个sql语句构建问题. 情形是这样的: 我需要获取不同小组下前N条记录. select top 10 * from dbo.Topic where GroupID in ...

  7. DataGridView默认不选中

    NurseGridList.CurrentCell = null;                NurseGridList.ClearSelection();                Nurs ...

  8. C#简单的tcpserver

    实现一个简单的TCPserver,用tcplistener实现. 当收到客户端特定信息"101"时,发送给客户端"202“指令. using System; using ...

  9. C# double float int string 与 byte数组 相互转化

    在做通信编程的时候,数据发送多采用串行发送方法,实际处理的时候多是以字节为单位进行处理的.在C/C++中 多字节变量与Byte进行转化时候比较方便 采用UNION即可废话少说看示例:typedef u ...

  10. 006.Compile方法

    Delphi procedure Compile; 类型:procedure 可见性:public 所在单元:System.RegularExpressionsCore 父类:TPerlRegEx 此 ...