hdu 3016 Man Down(线段树)

高并发系统性能瓶颈诊断与优化:从数据库连接池到SQL索引实战 在软件工程实践中,系统性能瓶颈往往源于资源管理与负载压力之间的失衡。从技术原理层面看,数据库连接池作为管理数据库连接的核心组件,其配置参数如最大连接数、超时时间等直接决定了系统在高并发下的吞吐能力。同时,SQL查询效率是影响数据库性能的关键因素,索引策略的合理运用能大幅降低查询延迟。这些技术的价值在于保障系统在高负载下的稳定性和响应速度,广泛应用于电商、金融、物联网等需要处理海量数据与实时请求的场景。本文聚焦于系统“力竭”状态的深度剖析,通过连接池耗尽与慢SQL这两个典型热词案例,提供从问题诊断到实战优化的 阅读详情

Man Down

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1171    Accepted Submission(s): 400


Problem Description
The Game “Man Down 100 floors” is an famous and interesting game.You can enjoy the game from
http://hi.baidu.com/abcdxyzk/blog/item/16398781b4f2a5d1bd3e1eed.html

We take a simplified version of this game. We have only two kinds of planks. One kind of the planks contains food and the other one contains nails. And if the man falls on the plank which contains food his energy will increase but if he falls on the plank which contains nails his energy will decrease. The man can only fall down vertically .We assume that the energy he can increase is unlimited and no borders exist on the left and the right.

First the man has total energy 100 and stands on the topmost plank of all. Then he can choose to go left or right to fall down. If he falls down from the position (Xi,Yi),he will fall onto the nearest plank which satisfies (xl <= xi <= xr)(xl is the leftmost position of the plank and xr is the rightmost).If no planks satisfies that, the man will fall onto the floor and he finishes his mission. But if the man’s energy is below or equal to 0 , he will die and the game is Over.

Now give you the height and position of all planks. And ask you whether the man can falls onto the floor successfully. If he can, try to calculate the maximum energy he can own when he is on the floor.(Assuming that the floor is infinite and its height is 0,and all the planks are located at different height).

Input
There are multiple test cases.

For each test case, The first line contains one integer N (2 <= N <= 100,000) representing the number of planks.

Then following N lines representing N planks, each line contain 4 integers (h,xl,xr,value)(h > 0, 0 < xl < xr < 100,000, -1000 <= value <= 1000), h represents the plank’s height, xl is the leftmost position of the plank and xr is the rightmost position. Value represents the energy the man will increase by( if value > 0) or decrease by( if value < 0) when he falls onto this plank.

Output
If the man can falls onto the floor successfully just output the maximum energy he can own when he is on the floor. But if the man can not fall down onto the floor anyway ,just output “-1”(not including the quote)

Sample Input
  
4 10 5 10 10 5 3 6 -100 4 7 11 20 2 2 1000 10

Sample Output
  
140

Source

Recommend
gaojie
 
一个木板,看成一个线段。找出最大的能力剩余。我的想法是从底部开始倒跳回去,将最后一块板看成是最大的覆盖所有区域的初始板能量为初值100;
energy[f]=max(energy[l],energy[r])+val(f);就是板的最左与最右跳下缩剩余的最大能量,一直跳到最高的板即是答案。
 
 
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100300
using namespace std;
class node
{
  public:
  int l,r,cover,val;
}root[N<<2];
class A
{
  public:
  int h,l,r,val;
}q[N];
bool cmp(A a,A b)
{
  return a.h<b.h;
}
void build(int t,int l,int r)
{
  root[t].l=l;root[t].r=r;
  if(root[t].l==root[t].r){root[t].cover=0;root[t].val=0;return;}
  build(t<<1,l,(l+r)/2);build(t<<1|1,(l+r)/2+1,r);
}
void update(int t,int l,int r,int val)
{
  if(root[t].l==l&&root[t].r==r){root[t].cover=1;root[t].val=val;}
  else
  {
    if(root[t].cover)
    {
      root[t<<1].cover=1;root[t<<1|1].cover=1;
      root[t<<1].val=root[t].val;root[t<<1|1].val=root[t].val;
      root[t].cover=0;root[t].val=0;
    }
    if(root[t<<1].r>=r)update(t<<1,l,r,val);
    else if(root[t<<1|1].l<=l)
    {
      update(t<<1|1,l,r,val);
    }
    else
    {update(t<<1,l,root[t<<1].r,val);
     update(t<<1|1,root[t<<1|1].l,r,val);
    }
  }
}
int query(int t,int pos)
{
  if(root[t].cover)
  {
    return root[t].val;
  }
  if(root[t<<1].r>=pos)
  query(t<<1,pos);
  else query(t<<1|1,pos);
}
int main()
{
  int m;
  while(cin>>m)
  {
    for(int i=0;i<m;i++)
    scanf("%d%d%d%d",&q[i].h,&q[i].l,&q[i].r,&q[i].val);
      sort(q,q+m,cmp);
      build(1,1,N);
      root[1].cover=1;root[1].val=100;
      int x;
      for(int i=0;i<m;i++)
      {
        x=max(query(1,q[i].l),query(1,q[i].r));
        update(1,q[i].l,q[i].r,q[i].val+x);
      }
      x=max(query(1,q[m-1].l),query(1,q[m-1].r));
      if(x<0)x=-1;
      cout<<x<<"\n";
  }
}

Mac电脑本地安装Stable Diffusion小白教程避开所有坑教程 如果出现黄字部分警告,如WARNING: The scripts pip, pip3 and pip3.9 are installed inz‘/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/bin’ which is not on PATH)需要将其添加到path。下载pip,输入:curl https://bootstrap.pypa.io/pip/get-pip.py -o get-pip.py。 阅读详情

相关推荐

基于PLC的矿用排水控制系统设计【附代码】

(3)矿用排水控制系统的软件设计 研究设计了矿用排水控制系统的软件,包括PLC程序的编写和上位机监控画面的设计。(2)矿用排水控制系统的硬件设计 研究对矿用排水控制系统的硬件进行了选型和设计,包括矿用多级耐磨离心泵、三相异步防爆电机等执行设备的选型,以及控制系统所需用到的各类型传感器、PLC的I/O点分配及选型。(1)矿用排水控制系统的现状分析 研究首先对矿井排水系统的现状进行了分析,指出了现有系统存在的问题,如自动化程度低、劳动强度大、设备维护困难等。✅ 具体问题可以私信或查看文章底部二维码。

lagougongzuoshi的博客 1189

HDU 3016 Man Down——线段树

传送门 Problem Description The Game “Man Down 100 floors” is an famous and interesting game.You can enjoy the game from We take a simplified version of this game. We have only two kinds of planks. One kind of the planks contains food and the other one contai

lllllan 221

使用DeepSeek、MCP和AKShare实现智能金融问答系统技术方案

DeepSeek是由深度求索公司开发的大规模语言模型,最新版本DeepSeek-V3采用混合专家(MoE)架构,拥有671B参数,激活37B参数,在多项基准测试中表现优异3。要使用DeepSeek的API服务:访问DeepSeek平台注册账号获取API Key(形如AKShare是基于Python的金融数据接口库,提供股票、基金、期货、宏观经济等领域的海量数据。主要特点包括:免费开源,数据源丰富支持多种数据格式(DataFrame/JSON)持续更新维护安装命令。

Kin 3199

HDU 3016 Man Down(线段树)

HDU 3016 Man Down 题目链接 题意:是男人就下100层的游戏的简单版,每次只能从两端下落,求落地最大血量 思路:利用线段树可以处理出每个线段能来自哪几个线段,然后就是dag最长路了 代码: #include #include #include #include using namespace std; const int N = 100005

Remilia's 1168

publisher与subscriber话题的消息类型md5sum不一致问题

[ERROR] [1604235557.591296096]: Client [/range_vision_fusion_01] wants topic /detection/vision_objects to have datatype/md5sum [autoware_msgs/DetectedObjectArray/13415342e539aa36ea9a6f04ffaf39b4], but our version has [autoware_msgs/DetectedObjectArray/c16a

cxhmike的博客 6626

【Unity】Pico VR 开发实战:从环境搭建到交互实现

本文是一份详细的Unity Pico VR开发实战指南,涵盖从环境搭建到核心交互实现的全流程。详细讲解了如何集成Pico Unity Integration SDK与XR Interaction Toolkit,配置开发环境,并重点解析了手柄输入处理、射线交互以及VR UI操作三大核心模块的代码实现与优化技巧,帮助开发者快速上手Pico VR应用开发。

rice5的博客 1191

【HDU】3016 Man Down 线段树DP

传送门:【HDU】3016 Man Down 题目分析:今天看tu

poursoul 1214

Mac 不小心断开移动硬盘导致磁盘无法读取和加载(顺利解决!)

Mac移动硬盘不正确断开连接导致无法读取加载的解决方法,亲测有效

Robin_Pi的博客 1万+

hdu 3016 Man Down 线段树+dp

这题的思路是:将板子根据高度从低到高排序。用线段树找到当前木板的左边和右边的下一个木板的id,不断覆盖新的木板。 然后用dp[i]表示在第i个木板的最大能量,根据找到的visl和visr不断下跳,找到最优解。 由于做题注意力不集中和对线段树不够熟悉。出现了3个错误,找了我好久,太粗心了。 #include #include #include using namespace std; #de

dimhat的专栏 694

清华源pip install出现ERROR: Could not find a version that satisfies the requirement的解决方案

本文主要介绍了清华源pip install出现ERROR: Could not find a version that satisfies the requirement的解决方案,希望能对学习python的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 8万+

Allegro16.6详细教程(二)

3-D Viewer,可以直接在allegro中看到board file的3-D顯示效果。3-D Viewer對於PCB Editor Products,只有環境變數中的OpenGL顯示功能開啟後才有效,而對於APD/SiP是無效的。2.3-D viewer是在一個獨立的視窗中打開的。3-D environment環境支援多種顯示內容的過濾,取景視角和顯示效果的選項,透過遊標可以直接控制放大,移動,翻轉等操作。

axingxiansen的博客 1944

hdu3016 Man Down(线段树+dp)

题目链接:点击这里 题目大意: 多组输入,每组输入给出 nnn 块木板,木板高度为 hhh 左右边界分别为 l,rl,rl,r 其还有一个属性为 valvalval,玩家初始有 100100100 滴血,玩家只能从当前木板的左右边界竖直向下跳,每跳到一块木板上玩家血量就会变化 valvalval (val可能小于0) ,求从最上面的木板跳到地面玩家的最大生命值 题目分析: 首先我们要知道如何确定能从当前木板跳到哪个木板上,这个我们可以让高度从小到大用线段树做一次染色,代码中的 near[i][0],near

羊驼的博客 237

Buck电源设计常见的一些问题(一)半桥栅极驱动芯片共性失效问题

半桥驱动芯片主要用在器件可应用于电信,数据通信,便携式存储或更低电压系统中的电源转换器,半桥、全桥、推挽、同步降压,正激变换器和同步整流器等方面。当然难免会遇到不少问题。基本上我们在产品开发的过程中都遇到过栅极驱动芯片坏掉的情况,所以找了一些资料,学习学习。也查找查找原因。

小幽余生不加糖 2384

HDU3016 Man Down(线段树)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3016 题意:有n块板子,一个人从最高的板子开始往下跳,每次只能从一个板子的左或者右端点往下跳,同一个高度只会有一块板子。问你到最下面,能获得的最大分数是多少。如果中间分数<0了,游戏直接结束,输出-1。 思路:这题想到线段树好像就可以直接模拟了。因为跳下来只能从左或者右,所以一块板子的价值就是l和r处

xtttgo的博客 738

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

HDU-3016 Man Down 线段树

http://acm.hdu.edu.cn/showproblem.php?pid=3016 这题是一个游戏题,名曰:是男人就下一百层。就是给定一系列的坐标,首先是纵坐标,然后是线段的左右坐标,最后是在该条线段的增加或者扣除的血量。 解决这题的关键在于如何处理这多条线段的关系,如果是从上而下的话,那么我们能够更新一条边的两个端点下的最优值,那么对于后面加入的边就有下面的动态方程:      s...

weixin_30347009的博客 106

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

hdu 3016 Man Down(线段树区间更新+dp)

题意: 是男人就下100层相信很多人都玩过,这题就是简单的模拟这个游戏。 有nn块木板,每块木板有4个属性,高h(h>0),左边界,右边界,以及掉落在它上面,获得多少生命值,一个人从最高的木板开始往下跳,初始时生命值为100,问最后掉落到地面能获得的生命值最多为多少(如果途中生命值为≤0,那么这个人会死去),如果无法跳到地面,输出-1。 解析: 既然只能垂直下落,而且是落在最近的板上,

小G的ACM之路 983

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

HDU 3016 Man Down(线段树 + DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3016 题意:一个人从高处往下垂直下落,每次可以从该木板的两端下落到最近的且包含该端点的木板上,一开始血量为100,跳到某个木板上可能回血或扣血,当血量 <= 0时该游戏结束,问跳到地面血量最多为多少 思路:首先要考虑如何寻找下次能跳的最近的左右两木板这一问题,我们可以将木板升序排...

Tongqi 584

HDU 3016 Man Down (线段树+dp)

Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1391    Accepted Submission(s): 483 Problem Description The Game “Man Down 1

炒饭君的博客 1341

hdu(3016) Man Down(线段树查询更新+dp)

这道题目可以说是游戏的简化版。 题目的大致意思是: 首先我们只有两种板,一种使能量增加,另一种却使能量减少。 最开始人物站在最高层,然后它一开始有100的生命值,它每次下落只能掉到离他最近的木板上去,当然他只能从左端点或者是右端点往下掉。 但是如果没有板满足如下情况的话,那么他就掉到最底下去了,如果此时他的能量小于等于0的话,那么他就会死亡,那么则输出-1;否则输出他所能获得能量的最大值。

ACM_hades的梦想之路 1004

Hdu 3016 Man Down【线段树+Dp】

Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2428    Accepted Submission(s): 893 Problem Description The Game “Man Down

mengxiang000000 455

hdu 3016 Man Down (线段树 + dp)

题目大意: 是男人就下一般层。。。没什么可以多说的吧。 注意只能垂直下落。 思路分析: 后面求最大值的过程很容易想到是一个dp的过程 。 因为每一个plane 都只能从左边 从右边下两种状态。 然后我们所需要处理的问题就是 ,你如何能快速知道往左边下到哪里,往右边下到哪里。 这就是线段树的预处理。 讲线段按照高度排序。 然后按照高度从小到大加入到树中。 然后去寻找左端点

Jinx Jinx again 951

线段树专辑—— hdu 3016 Man Down

http://acm.hdu.edu.cn/showproblem.php?pid=3016 挺有趣的一个以“是男人就下100层”为背景的题目,要求从最高处往下跳,跳到最下一层时候所得分数的最高值。 这题不难,首先将线段从低到高排序,用这些线段对区间进行染色,每次染色之前先询问一边从线段的左右节点跳下去所能到达的线段。记为一条路径。 最后从高到底根据我们所有的路径信息进行一次DP即可 Vi...

weixin_30328063的博客 104
上一篇: hdu 1166 敌兵布阵(线段树)
下一篇: hdu 4325 Flowers(线段树+哈希散列)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址