HDU 3016 Man Down(线段树)
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(线段树)的更多相关文章
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- HDU 5820 (可持久化线段树)
Problem Lights (HDU 5820) 题目大意 在一个大小为50000*50000的矩形中,有n个路灯.(n<=500000) 询问是否每一对路灯之间存在一条道路,使得长度为|x1 ...
- HDU 5861 Road (线段树)
Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...
- HDU 3577 Fast Arrangement (线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...
- hdu 3303 Harmony Forever (线段树 + 抽屉原理)
http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...
随机推荐
- js jquery 判断匹配元素是否存在
jQuery 判断页面元素是否存在的代码 在传统的Javascript里,当我们对某个页面元素进行某种操作前,最好先判断这个元素是否存在.原因是对一个不存在的元素进行操作是不允许的. 例如: 复制代码 ...
- Git学习总结(8)——Git和SVN之间的基本区别
GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果你是一个具有使用SVN背景的人,你需要做一定的思想转换,来适应GIT提供的一些概念和特征.所以,这篇文章的主要目的就是 ...
- oracle学习之第一个存储过程:打印Hello World
数据库对象:表.视图.索引.序列.同义词.存储过程.存储函数 存储过程:指的是存储在数据库中供全部用户程序调用的子程序叫存储过程.存储函数 存储过程和存储函数的同样点:完毕特定功能的程序 存储过程和存 ...
- 使用docker搭建hadoop分布式集群
使用docker搭建部署hadoop分布式集群 在网上找了非常长时间都没有找到使用docker搭建hadoop分布式集群的文档,没办法,仅仅能自己写一个了. 一:环境准备: 1:首先要有一个Cento ...
- ZOJ 3689 Digging(贪心+dp)
Digging Time Limit: 2 Seconds Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...
- Composer使用实践
Composer 是 PHP5.3以上 的一个依赖管理工具.它允许你声明项目所依赖的代码库,它会在你的项目中为你安装他们. 地址在这里 库地址 这里相当于php应用商店,存放着很多库. 这些库,基本上 ...
- [JZOJ 5465] [NOIP2017提高A组冲刺11.9] 道路重建 解题报告 (e-dcc+树的直径)
题目链接: http://172.16.0.132/senior/#main/show/5465 题目: 小X所居住的X国共有n个城市,有m条无向道路将其连接.作为一个统一的国家,X 城的任意两个城市 ...
- BZOJ 3175 最大独立集
思路: 最大独立集嘛 用nlogn的Dinic做 //By SiriusRen #include <queue> #include <cstdio> #include < ...
- ibatis annotations 注解方式返回刚插入的自增长主键ID的值--转
原文地址:http://www.blogs8.cn/posts/WWpt35l mybatis提供了注解方式编写sql,省去了配置并编写xml mapper文件的麻烦,今天遇到了获取自增长主键返回值的 ...
- HD-ACM算法专攻系列(11)——Exponentiation
问题描述: 源码: 考察对大数的计算,需要注意去除前导0与后导0. import java.math.BigDecimal; import java.util.*; public class Main ...