HA2795Billboard 可用线段树

#include<iostream>using namespace std;#include<cstdio>#include<algorithm>#define maxn 200005int h,n,w;int root[maxn<<4];int ans;//标记void make_tree(int l,int r,int rt){if(l==r){root[rt]=w;return ;}int mid=(r+l)/2;make_tree(l,mid,rt*2);make_tree(mid+1,r,rt*2+1);root[rt]=max(root[rt*2],root[rt*2+1]);}void query(int b,int l,int r,int rt){if(root[rt]<b)return ;if(l==r){root[rt]-=b;ans=l;return;}int mid=(l+r)/2;if(ans==-1) query(b,l,mid,rt*2);if(ans==-1) query(b,mid+1,r,rt*2+1);if(ans!=-1) root[rt]=max(root[rt*2],root[rt*2+1]);}int main(){while(scanf("%d%d%d",&h,&w,&n)!=EOF){if(h>200000) h=200000;make_tree(1,h,1);while(n--){int a;ans=-1;scanf("%d",&a);query(a,1,h,1);printf("%d\n",ans);}}return 0;}
View Code

 

第一眼又是坑长的英文,细看外加用了点灵格斯,题目大意是一个广告栏要加广告上去,输入广告栏的长(h)宽(w)和所加广告的个数n,然后n行依次输入n个数代表所加广告的宽(广告的长都是1),每一次加广告上去,都尽量把广告往左上位置放,每放一个广告输出它放在广告栏的第几行(长度),没有位置放则输出"-1"。

     用线段树,建树,每一个root[rt]=w,放广告就从左树先查找,长度从小到大,当满足root[rt]>n[i]能放广告时,记下left位置,并相应的减去x[i],输出left;不能放输出"-1"。

转载于:https://www.cnblogs.com/zlpzjy/p/3216313.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274144.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

axure下拉列表框单选框_如何在Axure中创建下拉菜单和组合框

axure下拉列表框单选框First, let’s clarify what exactly is a dropdown menu, and what is a combo box, aren’t they the same? Well … no, not really, let me explain.首先&#xff0c;让我们弄清楚什么是下拉菜单&#xff0c;什么是组合框&#xff0c;不是吗&#xf…

Android 第一课 Activity

以下说明基于Android Studio&#xff0c;简称AS。&#xff08;红色字体为自行添加&#xff0c;注在醒目&#xff09; 具体包括&#xff1a;创建活动创建项目 加载布局 在AndroidManifest文件中注册 活动中使用&#xff08;提醒&#xff09;Toast 在活动使用&#xff08;菜…

figma设计_一种在Figma中跟踪设计迭代的简单方法

figma设计As designers, telling a good story is always part of the job. A great story engages the client with the journey of decision making; it shows your team the breadth and depth of the exploration; it also encourages us to reflect on our own design pro…

Android 第二课 Intent

上一节&#xff0c;掌握了活动的创建&#xff0c;但是在启动器中点击应用的图标只会进入到该应用的主活动&#xff0c;那么&#xff0c;如何从主活动跳转到其他活动呢&#xff1f;显式IntentIntent有多个构造函数&#xff0c;其中一个是Intent(Context packContext,Class<?…

ok~加油!

你有梦想&#xff0c;放手去做&#xff01;转载于:https://www.cnblogs.com/the-one/p/3217124.html

latex 插图 上下放_专辑插图中上下文中的文本

latex 插图 上下放Especially if, like me, you’re not properly educated in the world of visual design, typography, and all those other things that a formal education can bring. We’re kind of playing around until something fits right, and doesn’t feel jarr…

亡羊补牢,为时不晚?

亡羊补牢&#xff0c;为时不晚 人总是想着第二次比第一次做的好&#xff0c;可是会一直有第二次机会吗&#xff1f;当你思考好&#xff0c;决定做一件事情的时候&#xff0c;为什么不坚持下去呢&#xff1f;当你思考好&#xff0c;记住坚持到底就会胜利。祝福自己&#xff0…

2013年7月份第4周51Aspx源码发布详情

大型企业通用管理ERP源码 2013-7-26 [VS2010]2013.7.4更新内容&#xff1a;1.修复决策模式-客户等级不能保存问题。2.修复企业知识库有报错问题。3.修复运营模式-人力资源分析模块-在部分模块点击查询后&#xff0c;水晶报表显示无法加载文件问题&#xff0c;4.修复行政办公模…

视觉感知_产品设计中的视觉感知

视觉感知The role of the UX designer has evolved immensely over time, but at its core, it remains the same- UX设计人员的角色随着时间的流逝而发生了巨大的变化&#xff0c;但从本质上讲&#xff0c;它保持不变- to deliver information to users in an effective mann…

Android 第三课 Activity的生命周期

新建项目ActivityLifeCycleTest&#xff0c;创建主活动后&#xff0c;再新建两个子活动--NormalActivity和DialogActivity。 现在活动及其对应布局文件创建完毕。 编辑normal_layout.xml文件&#xff0c;代码如下&#xff1a; <?xml version"1.0" encoding"…

转载:Apache commons开源工具简介

Apache Commons是一个非常有用的工具包&#xff0c;解决各种实际的通用问题&#xff0c;下面是一个简述表&#xff0c;详细信息访问http://jakarta.apache.org/commons/index.html BeanUtilsCommons-BeanUtils 提供对 Java 反射和自省API的包装 BetwixtBetwixt提供将 JavaBean …

pb 插入报列在此处不_获取有关[在此处插入问题]的事实

pb 插入报列在此处不Twitter’s recent move to put notices on tweets themselves is one of the most controversial social media features during our times. As a design technologist, I can’t help but wonder the decision-making process behind it. It’s a perfect…

设计模式_单实体模式

Singleton 三要素&#xff1a;private 构造函数、 public 静态方法、 public 静态变量 单实例模式的三种线程安全实现方式&#xff08;&#xff23;&#xff0b;&#xff0b;&#xff09; &#xff11; 懒汉模式&#xff1a;即第一次调用该类实例的时候才产生一个新的该类实例…

Android 第四课 活动的启动模式

启动模式分为4种&#xff0c;分别为standard&#xff0c;singleTop&#xff0c;singleTask&#xff0c;和singleInstance我们可以在AndroidManifest.xml中通过给<activity>标签指定android:launchMode属性来选择启动模式。standard standard是活动默认的启动模式。在stan…

c++编写托管dll_教程:如何编写简单的网站并免费托管

c编写托管dll本教程适用于谁&#xff1f; (Who is this tutorial for?) This tutorial assumes no prior knowledge and is suitable for complete beginners as a first project 本教程假定您没有先验知识&#xff0c;并且适合初学者作为第一个项目 您将需要什么 (What you w…

浅述WinForm多线程编程与Control.Invoke的应用

在WinForm开发中&#xff0c;我们通常不希望当窗体上点了某个按钮执行某个业务的时候&#xff0c;窗体就被卡死了&#xff0c;直到该业务执行完毕后才缓过来。一个最直接的方法便是使用多线程。多线程编程的方式在WinForm开发中必不可少。本文介绍在WinForm开发中如何使用多线程…

Android 第五课 常用控件的使用方法(TextView、Button、EditView、 ImageView、 ProgressBar、 ProgressDialog等)

总结&#xff1a;见名知意 TextView&#xff1a; Button: EditView: ImageView: ProgressBar: ProgressDialog和AlertDialog有些类似&#xff0c;都可以再界面弹出对话框&#xff0c;都能够屏蔽其他控件的交互能力&#xff0c;用法也类似。 我们还发现ProgressDialog和AlertDia…

设计 色彩 构图 创意_我们可以从时尚的创意方向中学到色彩

设计 色彩 构图 创意The application of fashion as a form of aesthetic expression is a notion familiar to many. Every day, we curate ourselves with inspiration from rising trends, a perception of our personal preferences, and regards to practicality in the c…

Android 第六课 4种基本布局之LinearLayout和Relativelayout

看完控件&#xff0c;紧接着看布局&#xff0c;布局是可以来放置控件&#xff0c;管理控件的。布局里也可以嵌套布局。我们新建项目UILayoutTest项目&#xff0c;活动名和布局名选择默认。加入活动及其对应的布局已经创建完成。线性布局(LinearLayout)android:layout_gravity属…

如何在UI设计中制作完美阴影

重点 (Top highlight)Shadows are everywhere in modern UI Designs. They are one of the most essential part of the UI elements right behind the fill, stroke, and cornder radius. &#x1f609;现代UI设计中到处都有阴影。 它们是UI元素中最重要的部分之一&#xff0c…