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. Spring IoC容器实现

    1,Spring的两种IoC容器 BeanFactory 基础类型的IoC容器: 采用延迟初始化策略(容器初始化完成后并不会创建bean的对象,只有当收到初始化请求时才进行初始化): 由于延迟初始化, ...

  2. maven小知识点

    Maven 使用惯例优于配置的原则 .它要求在没有定制之前,所有的项目都有如下的结构: 一个 maven 项目在默认情况下会产生 JAR 文件,另外 ,编译后 的 classes 会放在 basedi ...

  3. kentico version history and upgrade

    Version history Kentico 10: November 30, 2016 Kentico 9: November 24, 2015 Kentico 8.2: January 6, 2 ...

  4. RSA in .net and dotnet core

    dotnet RSAParameters Struct https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography ...

  5. ES task管理

    Task Management API The Task Management API is new and should still be considered a beta feature. Th ...

  6. 自己定义CNN网络模型并使用caffe训练

    caffe自带的例子中对mnist手写体数字训练使用的卷积神经网络是在lenet_train_test.prototxt中定义的,隐含层包含了2个卷积层,2个池化层,2个全连接层,1个激活函数层.网络 ...

  7. 3.QT计算机实战

    mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { c ...

  8. BZOJ 2301 莫比乌斯函数+分块

    思路: 同BZOJ1101 就是加个容斥 - http://blog.csdn.net/qq_31785871/article/details/54340241 //By SiriusRen #inc ...

  9. POJ 3657 并查集

    题意: 思路: 1.二分+线段树(但是会TLE 本地测没有任何问题,但是POJ上就是会挂--) 2.二分+并查集 我搞了一下午+一晚上才搞出来----..(多半时间是在查错) 首先 如果我们想知道这头 ...

  10. C#语言基础之第一个C#程序

    1.在记事本中编写如下代码,保存为Simple.cs文件. using System; class Hello World{ public static void Main(){ Console.Wr ...