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. 读取bin文件,并且按结构体赋值打印

    目标:读取一个bin文件,并且将bin文件中的数据,按字节对齐赋值给结构体,并且打印出结构体的内容 目前思路是简单的先将bin文件数据一次性读到一个数组中,再将数组强制转换为结构体 ] FILE *f ...

  2. 2015 Multi-University Training Contest 5 hdu 5352 MZL's City

    MZL's City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. STL_算法_对全部元素排序(sort、stable_sort)

    C++ Primer 学习中. . .   简单记录下我的学习过程 (代码为主) //大部分容器适用.不适用于list容器 sort(b,e) sort(b,e,p) stable_sort(b,e) ...

  4. 编写html经常使用而又easy忘记的语句

    设置文件字符编码: <meta charset="utf-8"> 内部样式表: <style type="text/css"> hr { ...

  5. ORA-38760: This database instance failed to turn on flashback database

    ORA-38760: This database instance failed to turn on flashback database 问题背景:        測试数据库运行shutdown ...

  6. 浅谈关于collection接口及相关容器类(一)

    Collection在英文单词的意思是:採集,收集. 而在JAVA API 文档中它是一个收集数据对象的容器. Collection作为容器类的根接口.例如以下图(部分子接口未写出): waterma ...

  7. Spring中@Transactional事务回滚(含实例具体解说,附源代码)

    一.使用场景举例 在了解@Transactional怎么用之前我们必须要先知道@Transactional有什么用. 以下举个栗子:比方一个部门里面有非常多成员,这两者分别保存在部门表和成员表里面,在 ...

  8. Win7上从硬盘安装Debian

    近期一直想将笔记本搞成Win7+Debian双系统.由于无论怎样优化,2G内存的Win7笔记本上开个Linux虚拟机都实在吃力. 经过一段时间的资料搜索.并阅读Debian官方的安装文档,今天最终实现 ...

  9. ZOJ 3689 Digging(贪心+dp)

    Digging Time Limit: 2 Seconds      Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...

  10. MLPclassifier,MLP 多层感知器的的缩写(Multi-layer Perceptron)

    先看代码(sklearn的示例代码): from sklearn.neural_network import MLPClassifier X = [[0., 0.], [1., 1.]] y = [0 ...