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.pswp.cn/news/274144.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274144.shtml
英文地址,請注明出處:http://en.pswp.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…