HDU 3016 Man Down

题目链接

题意:是男人就下100层的游戏的简单版,每次仅仅能从两端下落。求落地最大血量

思路:利用线段树能够处理出每一个线段能来自哪几个线段。然后就是dag最长路了

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int N = 100005; int n; struct Line {
int l, r, y, val;
Line() {}
Line(int l, int r, int y, int val) {
this->l = l; this->r = r;
this->y = y; this->val = val;
}
void read() {
scanf("%d%d%d%d", &y, &l, &r, &val);
}
} line[N]; bool cmp(Line a, Line b) {
return a.y < b.y;
} #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) struct Node {
int l, r, id, lazy;
void gao(int v) {
lazy = v;
id = v;
}
} node[4 * N]; void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r;
node[x].id = node[x].lazy = -1;
if (l == r) return;
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
} void pushdown(int x) {
if (node[x].lazy != -1) {
node[lson(x)].gao(node[x].lazy);
node[rson(x)].gao(node[x].lazy);
node[x].lazy = -1;
}
} void add(int l, int r, int v, int x = 0) {
if (node[x].l >= l && node[x].r <= r) {
node[x].gao(v);
return;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / 2;
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
} int query(int v, int x = 0) {
if (node[x].l == node[x].r) return node[x].id;
int mid = (node[x].l + node[x].r) / 2;
pushdown(x);
if (v <= mid) return query(v, lson(x));
if (v > mid) return query(v, rson(x));
} const int INF = 0x3f3f3f3f; int dp[N]; vector<int> g[N]; int main() {
while (~scanf("%d", &n)) {
build(0, 100000);
line[n] = Line(0, 100000, 0, 0);
for (int i = 0; i < n; i++) {
line[i].read();
g[i].clear();
}
n++;
sort(line, line + n, cmp);
for (int i = 0; i < n; i++) {
if (i) {
int tol = query(line[i].l);
int tor = query(line[i].r);
g[tol].push_back(i);
if (tol != tor)
g[tor].push_back(i);
}
add(line[i].l, line[i].r, i);
}
line[n - 1].val += 100;
dp[n - 1] = line[n - 1].val;
for (int i = n - 2; i >= 0; i--) {
dp[i] = -INF;
for (int j = 0; j < g[i].size(); j++)
dp[i] = max(dp[i], dp[g[i][j]] + line[i].val);
}
if (dp[0] <= 0) dp[0] = -1;
printf("%d\n", dp[0]);
}
return 0;
}

HDU 3016 Man Down(线段树)的更多相关文章

  1. hdu 5700区间交(线段树)

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  2. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  3. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  4. HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  5. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  6. HDU 5820 (可持久化线段树)

    Problem Lights (HDU 5820) 题目大意 在一个大小为50000*50000的矩形中,有n个路灯.(n<=500000) 询问是否每一对路灯之间存在一条道路,使得长度为|x1 ...

  7. HDU 5861 Road (线段树)

    Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...

  8. HDU 3577 Fast Arrangement (线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...

  9. hdu 3303 Harmony Forever (线段树 + 抽屉原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...

随机推荐

  1. SpringBoot 消费NSQ消息

    使用监听器,来实现实时消费nsq的消息 一.目前spring boot中支持的事件类型如下 ApplicationFailedEvent:该事件为spring boot启动失败时的操作 Applica ...

  2. mysql5.7官网直译SQL语句优化--select语句优化

    8.2 sql语句优化 大致内容如下: 8.2.1:SELECT语句的优化 8.2.2:优化子查询,派生表和试图引用 8.2.3:优化INFORMATION_SCHEMA查询 8.2.4:优化数据改变 ...

  3. bzoj3626【LNOI2014】LCA

    3626: [LNOI2014]LCA Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1266  Solved: 448 [Submit][Stat ...

  4. 暑假NOIP期末考试【1】—— Phantom

    Phantom •题目名称: phantom •时间限制:1 秒 •空间限制:256 MiB 题目描写叙述 在一个无限大的棋盘上.排列着 n * n 枚棋子,形成一个 n 行 n 列的方阵.棋子能够横 ...

  5. [React] Unit test a React Render Prop component

    In this lesson, I use Enzyme and Jest to unit test a Counter Render Prop component. Writing integrat ...

  6. Genymotion出现Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE错误解决方法

    今天在Genymotion上执行曾经的一个项目(libs中有多个SDK和so文件)时,出现下面错误: Console控制台中:Installation error: INSTALL_FAILED_CP ...

  7. HDU 5187 zhx&#39;s contest(防爆__int64 )

    Problem Description As one of the most powerful brushes, zhx is required to give his juniors n probl ...

  8. C++ STL 源代码学习(之deque篇)

    stl_deque.h /** Class invariants: * For any nonsingular iterator i: * i.node is the address of an el ...

  9. Linux内核编译測试

    内核编译: Step 1:配置内核编译选项. make menuconfig Optional Step :排除编译结果文件(.o)等之间的依赖性. make mrproper Optional St ...

  10. scanf使用与运算符

    scanf接收输入 #include <stdio.h> #include <stdlib.h> // 接收用户输入的小写字母,输出大写字母 int main() { char ...