hdu 4302 Holedox Eating(线段树或MAP,SET,4级)

Android开发者必看:手把手教你用avbtool生成vbmeta.img镜像(附完整命令解析) 本文为Android开发者提供了使用avbtool生成vbmeta.img镜像的完整实践指南。文章深入解析了Android Verified Boot 2.0框架中vbmeta.img的核心作用,详细拆解了avbtool make_vbmeta_image命令的关键参数,并对比了链式验证与直接包含描述符两种集成方式的差异。同时,提供了从手动生成到集成至Android构建系统(BoardConfig.mk)的深度定制方法,帮助开发者彻底掌握验证启动镜像的构建流程。 阅读详情

Holedox Eating

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2341    Accepted Submission(s): 792


Problem Description
Holedox is a small animal which can be considered as one point. It lives in a straight pipe whose length is L. Holedox can only move along the pipe. Cakes may appear anywhere in the pipe, from time to time. When Holedox wants to eat cakes, it always goes to the nearest one and eats it. If there are many pieces of cake in different directions Holedox can choose, Holedox will choose one in the direction which is the direction of its last movement. If there are no cakes present, Holedox just stays where it is.
 

Input
The input consists of several test cases. The first line of the input contains a single integer T (1 <= T <= 10), the number of test cases, followed by the input data for each test case.The first line of each case contains two integers L,n(1<=L,n<=100000), representing the length of the pipe, and the number of events.
The next n lines, each line describes an event. 0 x(0<=x<=L, x is a integer) represents a piece of cake appears in the x position; 1 represent Holedox wants to eat a cake.
In each case, Holedox always starts off at the position 0.
 

Output
Output the total distance Holedox will move. Holedox don’t need to return to the position 0.
 

Sample Input
  
3 10 8 0 1 0 5 1 0 2 0 0 1 1 1 10 7 0 1 0 5 1 0 2 0 0 1 1 10 8 0 1 0 1 0 5 1 0 2 0 0 1 1
 

Sample Output
  
Case 1: 9 Case 2: 4 Case 3: 2
 

Author
BUPT
 

Source
 

Recommend
zhuyuanchen520

思路:模拟就行了,如果是用线段树,那就找0->pos的最大值和pos->L的最小值,线段树存插入区间断最大值和最小值。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define lson t<<1
#define rson t<<1|1
#define mid (l+r)/2
using namespace std;
const int oo=1e9;
const int mm=1e5+9;
class node
{
 public:int mi,ma,l,r,num;
}rt[mm*4];
int L,n;
void build(int t,int l,int r)
{
 rt[t].l=l;rt[t].r=r;rt[t].num=0;rt[t].mi=oo;rt[t].ma=-oo;
 if(l==r){return;}
 build(lson,l,mid);build(rson,mid+1,r);
}
void update(int t,int id,bool flag)
{
 if(rt[t].l==rt[t].r&&rt[t].l==id)
 {
 if(flag){rt[t].num++;rt[t].mi=rt[t].ma=id;}
 else {rt[t].num--;if(!rt[t].num)rt[t].ma=-oo,rt[t].mi=oo;}
 return;
 }
 if(rt[lson].r>=id)update(lson,id,flag);
 else update(rson,id,flag);
 rt[t].num=rt[lson].num+rt[rson].num;
 rt[t].ma=max(rt[lson].ma,rt[rson].ma);
 rt[t].mi=min(rt[lson].mi,rt[rson].mi);
}
int query(int t,int l,int r,bool flag)
{
  if(l<=rt[t].l&&rt[t].r<=r)
  {
   if(flag)return rt[t].ma;
   else return rt[t].mi;
  }
  int ret;
  if(flag)ret=-oo;
  else ret=oo;
  if(l<=rt[lson].r)
  {if(flag)ret=max(ret,query(lson,l,r,flag));
   else ret=min(ret,query(lson,l,r,flag));
  }
  if(r>=rt[rson].l)
  {if(flag)ret=max(ret,query(rson,l,r,flag));
   else ret=min(ret,query(rson,l,r,flag));
  }
  return ret;
}
int main()
{
 int cas,a,b,num,ans;bool dir;
 while(~scanf("%d",&cas))
 {for(int ca=1;ca<=cas;++ca)
  {
  scanf("%d%d",&L,&n);
 /// puts("yes");
  build(1,0,L);
  dir=1;int pos=0;ans=num=0;
  for(int i=0;i<n;++i)
  {
   scanf("%d",&a);
   if(!a)
   {
   scanf("%d",&b);update(1,b,1);++num;
   }
   else
   { if(!num)continue;--num;
    int ll=query(1,0,pos,1);
    int rr=query(1,pos,L,0);
    ///cout<<ll<<" "<<rr<<" "<<ans<<endl;
    if(ll==-oo){ans+=rr-pos;update(1,rr,0);pos=rr;dir=1;continue;}
    if(rr==oo){ans+=pos-ll;update(1,ll,0);pos=ll;dir=0;continue;}
    a=pos-ll;b=rr-pos;
    if(a<b){ans+=a;update(1,ll,0);pos=ll;dir=0;continue;}
    else if(a>b){ans+=b;update(1,rr,0);pos=rr;dir=1;continue;}
    else if(a==b)
    {
      if(dir){ans+=b;update(1,rr,0);pos=rr;dir=1;continue;}
      else {ans+=a;update(1,ll,0);pos=ll;dir=0;continue;}
    }
   }
  }
  printf("Case %d: %d\n",ca,ans);
  }
 }
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
map<int,int>mp;
const int oo=1e9;
bool dir;
map<int,int>::iterator it,il,ir;
int main()
{
  int cas,l,n,a,b,num;
    while(~scanf("%d",&cas))
    {for(int ca=1;ca<=cas;++ca)
     {mp.clear();mp[oo]=1;mp[-oo]=1;
     num=0;mp[0]=1;
     it=il=ir=mp.find(0);
     int ans=0;dir=1;
     scanf("%d%d",&l,&n);
     for(int i=0;i<n;++i)
     {
       scanf("%d",&a);
       if(!a)
       {++num;
       scanf("%d",&a);mp[a]++;
       }
       else
       { if(!num)continue;--num;
       il=ir=it;
       --il;++ir;
        int z=it->first;
         --mp[z];///去除z
         if(mp[z]){continue;}
         else mp.erase(it);
         if(il->first==-oo){ans+=ir->first-it->first;it=ir;dir=1;continue;}
         if(ir->first==oo){ans+=it->first-il->first;it=il;dir=0;continue;}

         a=it->first-il->first;b=ir->first-it->first;
         if(a<b){ans+=a;it=il;dir=0;continue;}
         else if(a>b){ans+=b;it=ir;dir=1;continue;}
         else if(a==b)
         {if(dir){ans+=b;it=ir;}
          else {ans+=a;it=il;}
         }
       }
     }
     printf("Case %d: %d\n",ca,ans);

     }
    }
}



Android AVB实战:手把手教你配置avbtool生成vbmeta.img(附常见错误排查) 本文提供Android AVB(Verified Boot)实战指南,手把手教你配置avbtool生成vbmeta.img。内容涵盖从密钥管理、为boot/system分区添加验证信息,到构建核心vbmeta镜像及实现链式分区的完整流程,并附有集成到AOSP构建系统的方法与常见启动错误的深度排查方案,助力开发者快速掌握Android安全启动配置。 阅读详情

相关推荐

逆向解析AVB签名流程:从avbtool源码看Android启动验证的底层实现

本文深入解析Android Verified Boot(AVB)的底层实现,通过avbtool源码分析RSA-PSS签名验证在vbmeta镜像中的应用,揭示密钥吊销列表处理、哈希树递归校验等关键流程。为安全研究人员提供固件验证的实用方法论,涵盖VBMeta结构体解析、RSA签名验证及哈希树机制等核心内容。

sql99的博客 237

android avbtool工具用法

官方avbtool文档,Image结构说明 https://android.googlesource.com/platform/external/avb/+/master/README.md#Using-avbtool

liu-yonggang的专栏 1万+

android AVB2.0(一)工作原理及编译配置

android AVB2.0学习总结(一)

楼中望月 2万+

avbtool的使用

/将经过AVBtool签名的image_name加进现有的vbmeta.bin 中。//生成vbmeta_system.img(key可以不用)

weixin_50268209的博客 1289

Android14之绕过vbmeta.img签名校验实战:avbtool与fastboot的进阶应用

本文详细介绍了在Android14系统中如何通过avbtool与fastboot工具绕过vbmeta.img的签名校验,实现开发效率的提升。内容包括vbmeta.img的结构解析、环境搭建、生成禁用校验的镜像、安全刷入步骤以及故障排查方法,适用于需要快速迭代开发的Android开发者。

weixin_29196315的博客 321

avbtool.py查看boot.img、system.img、vbmeta.img签名信息工具

avbtool.py查看boot.img、system.img、vbmeta.img签名信息工具, linux平台用法: $ sudo apt install python2.7 $ python2.7 avbtool.py info_image --image boot.img 其中 boot.img为你需要查看的img文件路径 windows平台需要字节研究,理论也可以用的。

HDU 4302 Holedox Eating

多校的时候这题写了一个多小时....调了半个多小时过完样例, 然后一直wa..... 当时何其悲惨....其实也是很傻逼的一道, 就是模拟动物走的部分要写得仔细一点....尽量分模块写... 线段树: 单点更新, 区间查询, 维护区间离端点最近的有食物位置. 注意题目线段是0~n. 代码: #include #include #include #include #incl

tclh123 - 悲剧的泳裤王子 617

Android中签名原理

Android中的签名原理解析

hdu 4302 Holedox Eating(优先队列)

题意:有一个小动物在长L的数轴上,最开始这只小动物在0点,每个时候,有可能有两种事件,第一种是数轴上某一点会出现一份食物,另一种是小动物想找吃的,这种情况小动物会找最近的一个食物,然后过去,如果两边的食物距离相同,那么就按最后一次移动的方向去,如果两边都没有食物,就呆在原地。 思路:刚开始想用线段树做来着,但是想了想感觉好麻烦,后来想这题其实就是从左边找个最大值,从右边找个最小值嘛,那就可以用两

绝望的乐园 996

Python实战:用pdfplumber从PDF中精准提取表格数据(附完整代码)

本文详细介绍了如何使用Python库pdfplumber从PDF中精准提取表格数据,包括环境配置、标准与复杂表格处理策略、数据清洗与验证等实战技巧。通过完整代码示例,帮助数据分析师和财务专业人士实现PDF数据提取的自动化,提升工作效率。

weixin_29061821的博客 400

word 2013 长篇文档排版案例教程

office 2013 制作长文格式模板

1万+

Android14之禁止vbmeta.img签名校验(一百九十)

本篇目的:Android14之解决编译报错:bazel: no such file or directoryAndroid中的avbtool是一个命令行工具,它是Android Verified Boot(AVB)系统的一部分。AVB是一个安全特性,旨在通过分段和校验来保护Android设备上的启动过程,确保设备只启动经过验证的、未被篡改的软件。avbtool的主要作用包括:校验和生成分段:它用于对设备上的软件分段进行校验和生成。

Android系统攻城狮 8497

Playwright自动化测试实战:攻克日历时间控件三大策略与Java实现

在Web自动化测试领域,元素定位与交互模拟是核心技术基础,其原理在于通过程序精确识别并操作页面中的DOM元素,以模拟真实用户行为。这项技术的核心价值在于提升测试效率、确保交互逻辑的覆盖度与可靠性,广泛应用于电商、金融、OA等系统的功能验证。日历时间控件作为典型的复杂交互组件,常涉及动态弹出层、多级导航与状态同步,是自动化测试中的常见难点。本文聚焦于使用Playwright工具,针对此类控件深入剖析了三种核心解决策略:从最高效的直接赋值、到全面模拟用户交互的主流方法,再到利用组件特性的混合定位方案,并结合Ja

weixin_28835551的博客 311

Android P 如何挂载system镜像到根目录

Android O/P 版本以来,谷歌加入了A/B system的特性,此时ramdisk和system是一起放在同一个system.img镜像中的。而系统起来之后也就不存在system分区了,而是直接把system镜像挂载到/根目录上。那么这个操作是怎么进行的呢? system.img默认是需要使能dm-verity来挂载的,那么这就涉及到如何使能dm-verity来挂载/根分区。还有一个重要的...

程序猿Ricky的日常干货 1万+

Windows-Anaconda3+TensorFlow安装教程

测试环境:win10-64位和win7-64位 (系统必须是64位,因为TensorFlow目前只支持64位) 一、安装Anaconda3 1.下载Anaconda3 Anaconda官网链接:link 这里我们选择Windows版本,python3.6-version-64位,如下图所示。 2.下载完成之后,点击安装Anaconda3 注意:安装过程中要选择添加环境变量,如图 待安装完成...

DoctorCuiLab的博客 3086

平面变压器PCB绕组设计实战:从原理到布局的工程考量

本文深入探讨了平面变压器PCB绕组设计的工程实践,从基础原理到布局优化,涵盖了电流密度、层间绝缘、绕组拓扑结构等关键参数。通过实战案例分享,解析了高频应用中的集肤效应、邻近效应等挑战,并提供了热管理和EMC优化的实用技巧,助力工程师在服务器电源、车载充电器等空间敏感场景实现高效设计。

weixin_42666036的博客 453

avb签名流程

安卓系统在启动的时候,需要保证每个镜像挂载的完整性和安全性。所以需要一套开机安全机制。所以就有avb。avb签名已经来到了2.0版本。学习avb签名流程,其实就是学习现代的数字签名。

xuanfengwuxiang的博客 2698

Python DEAP 库深度解析:从基础架构到高级应用

DEAP 是一个基于 Python 的开源框架,专门用于实现和运行各种进化算法,旨在帮助用户轻松地构建和调整进化算法,用于解决各种优化和搜索问题。本节中,介绍了 DEAP 相较于其它进化计算框架的优势,以及 DEAP 中重要的工具 creator 和 Toolbox。

盼小辉丶的博客 5084

AVB数据解析:Android verified boot 2.0 vbmeta 数据结构解析

验证启动(Verified Boot)是Android一个重要的安全功能,主要是为了访问启动镜像被篡改,提高系统的抗攻击能力,简单描述做法就是在启动过程中增加一条校验链。,而各家实际做法和研发能力不尽相同,为了让设备厂商更方便的引入 Verified boot 功能,,好处是既保证了基于该框架开发的verified boot 功能能够满足 CDD 要求,也保留了各家 OEM 定制启动校验流程的弹性。这个弹性体现在哪里?

叫好与叫座虽然不是对立面,但想在同一个作品中达到双重效果很难。 3941

ESP32S3 TLS 握手WIFI可用但是在蜂窝热点下卡死:排查方法与根因

设备卡在等。

摸鱼专家 86

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

了解一下,Android 10中镜像文件的制作

缘起写《深入理解Android Java虚拟机ART》一书的时候,我自己做了基于模拟器使用的系统镜像,供我学习ART使用。编译系统镜像的步骤是这样的:先创建一个avd设备,取个名字,比如...

Innost的专栏 1万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Android AVB 分析(六)FEC 数据到底是如何生成的?

Android 编译时会调用 avbtool 对 system, vendor, product 等镜像生成 hashtree,但对于大的镜像,还会在 hashtree 之后生成用于纠错的 FEC 数据。那这个 FEC 到底是如何生成的呢?本篇以 android-13.0.0_r41 中编译 aosp_panther 目标的 system 镜像为例。探究下 system.img 的 FEC 数据到底是如何生成的。

洛奇看世界 1902

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Android AVB 分析(三)boot.img 到底包含了哪些数据?

在学习 Android Verify Boot 时,boot.img 都包含哪些数据,你有尝试亲自去分析 boot.img 吗?一个 boot 分区的镜像,为了满足 AVB 需要,需要进行如何处理?本文以实际操作的形式,带你查看 boot.img 镜像,包括 avbtool 的多个操作,以及如何如何手动解析 AVB Footer,如何使用 shell 命令验证带有 salt 的镜像 hash 值。

洛奇看世界 3039

Android P/Q MTK平台无依赖打包boot.img

背景: 有时排查版本问题,需要用到替换img的方式来查找问题出现在哪个img,若出现在bootimg,那到底是kernel、DTB 还是ramdisk。此时就需要单独替换其中一个的方式来打包,之前直接make bootimage-nodeps就可以了,但现在发现执行这个命令无效了。下面就分析下新版本如何找到正确的打包命令。 一、找到编译boot的命令 之前Android编译log里就会把make boot等img的指令打印出来,现在这个log也没有了,那就只能自己修改Makefile 把...

u013463707的专栏 1561

Magisk root 原理分析之二 :Android Verified Boot (AVB)

1. Android Verified Boot (AVB) 或称 Verified Boot 2.0 简介 官方解释:验证用户设备上运行的软件完整性。它通常从设备固件的只读部分开始,该部分加载代码并仅在通过密码验证代码是授权的并且没有任何已知的安全漏洞之后才执行代码。 AVB 2.0 引入一个新的分区:vbmeta.img(verified boot metadata),其包含分区的哈希, 下...

Kian_G 的博客 1万+
上一篇: hdu 4308 Saving Princess claire_(bfs,4级)
下一篇: uva 11520 - Fill the Square(枚举,2级)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值