BZOJ 1113: [Poi2008]海報PLA

1113: [Poi2008]海報PLA

Time Limit:?10 Sec??Memory Limit:?162 MB
Submit:?1025??Solved:?679
[Submit][Status][Discuss]

Description

N個矩形,排成一排. 現在希望用盡量少的矩形海報Cover住它們.

Input

第一行給出數字N,代表有N個矩形.N在[1,250000] 下面N行,每行給出矩形的長與寬.其值在[1,1000000000]2 1/2 Postering

Output

最少數量的海報數.

Sample Input

5
1 2
1 3
2 2
2 5
1 4

Sample Output

4

HINT

Source

[Submit][Status][Discuss]

?

分析

單調棧

代碼

  1 /*<--- Opinion --->*/
  2 
  3    #define HEADER
  4    #define MYMATH
  5 // #define FILEIO
  6 // #define FSTREAM
  7 // #define FREOPEN
  8    #define FASTREAD
  9    #define SHORTNAME
 10 
 11 ///// HEADER FILE /////
 12 
 13 #ifdef HEADER
 14 
 15 #include <cmath>
 16 #include <string>
 17 #include <cstdio>
 18 #include <cstring>
 19 #include <cstdlib>
 20 #include <algorithm>
 21 
 22 #include <sstream>
 23 #include <fstream>
 24 #include <iostream>
 25 
 26 #include <set>
 27 #include <map>
 28 #include <list>
 29 #include <queue>
 30 #include <stack>
 31 #include <vector>
 32 #include <utility>
 33 #include <functional>
 34 
 35 #endif
 36 
 37 ///// SHORTNAME /////
 38 
 39 #ifdef SHORTNAME
 40 
 41 #define LL long long
 42 #define ll long long
 43 #define re register
 44 #define un unsigned
 45 #define rb re bool
 46 #define ri re int
 47 #define ui un int
 48 #define rl re LL
 49 #define ul un LL
 50 
 51 #define rep (x, y) for (ri i = x; i <= y; ++i)
 52 #define repi(x, y) for (ri i = x; i <= y; ++i)
 53 #define repj(x, y) for (ri j = x; j <= y; ++j)
 54 #define repk(x, y) for (ri k = x; k <= y; ++k)
 55 
 56 #define upto(x) for (ri i = 1; i <= x; ++i)
 57 #define dnto(x) for (ri i = x; i >= 1; --i)
 58 
 59 #define up(x) for (ri i = 1; i <= x; ++i)
 60 #define dn(x) for (ri i = x; i >= 1; --i)
 61 
 62 #define put(x)   printf("%lld ",  (LL)x)
 63 #define putln(x) printf("%lld\n", (LL)x)
 64 
 65 #endif
 66 
 67 ///// FASTREAD /////
 68 
 69 #ifdef FASTREAD
 70 
 71 const int FR_lim = 10000000;
 72 
 73 char *FR_c;
 74 
 75 inline void fsetup(FILE *FR_file)
 76 {
 77     FR_c = new char[FR_lim];
 78     fread(FR_c, 1, FR_lim, FR_file);
 79 }
 80 
 81 template <class T>
 82 inline void fread(T &FR_num)
 83 {
 84     FR_num = 0; rb FR_neg = 0;
 85 
 86     while (*FR_c < '0')
 87         if (*FR_c++ == '-')
 88             FR_neg ^= true;
 89 
 90     while (*FR_c >= '0')
 91         FR_num = FR_num*10 + *FR_c++ - '0';
 92 
 93     if(FR_neg)FR_num = -FR_num;
 94 }
 95 
 96 #endif
 97 
 98 ///// FILE I/O /////
 99 
100 #ifdef FILEIO
101 
102 FILE *FIN = fopen("input.txt", "r");
103 FILE *FOUT = fopen("output.txt", "w");
104 
105 #ifndef FSTREAM
106 
107 #define fin FIN
108 #define fout FOUT
109 
110 #endif
111 
112 #endif
113 
114 ///// FSTREAM /////
115 
116 #ifdef FSTREAM
117 
118 std::ifstream fin("input.txt");
119 std::ofstream fout("output.txt");
120 
121 #endif
122 
123 ///// MYMATH /////
124 
125 #ifdef MYMATH
126 
127 #define min(a, b) (a < b ? a : b)
128 #define max(a, b) (a > b ? a : b)
129 
130 #define Min(a, b) a = min(a, b)
131 #define Max(a, b) a = max(a, b)
132 
133 #define abs(x) (x < 0 ? -x : x)
134 
135 #define sqr(x) ((x)*(x))
136 
137 #endif
138 
139 ///// _MAIN_ /////
140 
141 void _main_(void);
142 
143 signed main(void)
144 {
145 
146 #ifdef FREOPEN
147     freopen("input.txt", "r", stdin);
148     freopen("output.txt", "w", stdout);
149 #endif
150 
151     _main_();
152 
153 #ifdef FILEIO
154     fclose(FIN);
155     fclose(FOUT);
156 #endif
157 
158 #ifdef FREOPEN
159     fclose(stdin);
160     fclose(stdout);
161 #endif
162 
163 #ifdef FSTREAM
164     fin.close();
165     fout.close();
166 #endif
167 
168     return 0;
169 }
170 
171 /*<--- Main --->*/
172 
173 #define N 250005
174 
175 int n;
176 int ans;
177 int h[N];
178 int stk[N];
179 int tot = 0;
180 
181 void _main_(void)
182 {
183     fsetup(stdin);
184     
185     fread(n);
186     
187     ri x;
188     
189     up(n)
190     {
191         fread(x); fread(x);
192         while (tot && stk[tot] > x)--tot;
193         if (tot && stk[tot] == x)++ans;
194         stk[++tot] = x;
195     }
196     
197     putln(n - ans);
198 }
BZOJ_1113.cpp

好像那天特別高興的樣子,不知不覺就敲了個不明所以的模板,?補一份正常的代碼。

 1 #include <bits/stdc++.h>
 2 signed main(void) {
 3     int n, tot = 0;
 4     scanf("%d", &n);
 5     std::stack<int> stk;
 6     for (int i = 1; i <= n; ++i) {
 7         int h; scanf("%*d%d", &h);
 8         while (!stk.empty() && h < stk.top())
 9             stk.pop();
10         if (!stk.empty() && h == stk.top())
11             ++tot;
12         stk.push(h);
13     }
14     printf("%d\n", n - tot);
15 }
BZOJ_1113.cpp

?

?

@Author: YouSiki

轉載于:https://www.cnblogs.com/yousiki/p/6091683.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394580.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394580.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394580.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python自動化運維之常用模塊—OS

os模塊的作用&#xff1a;  os&#xff0c;語義為操作系統&#xff0c;所以肯定就是操作系統相關的功能了&#xff0c;可以處理文件和目錄這些我們日常手動需要做的操作&#xff0c;就比如說&#xff1a;顯示當前目錄下所有文件/刪除某個文件/獲取文件大小……  另外&#…

opengl三維圖形圖形顏色_【圖形學基礎】基本概念

右手坐標系。類似OpenGL遵循的右手坐標系&#xff1a;首先它是三維的笛卡爾坐標系&#xff1a;原點在屏幕正中&#xff0c;x軸從屏幕左向右&#xff0c;最左是-1&#xff0c;最右是1&#xff1b;y軸從屏幕下向上&#xff0c;最下是-1&#xff0c;最上是1&#xff1b;z軸從屏幕里…

xp職稱計算機考試題庫,2015年職稱計算機考試XP題庫.doc

2015年職稱計算機考試XP題庫.doc (7頁)本資源提供全文預覽&#xff0c;點擊全文預覽即可全文預覽,如果喜歡文檔就下載吧&#xff0c;查找使用更方便哦&#xff01;9.90 積分&#xfeff;2015年職稱計算機考試XP題庫職稱計算機考試考點精編&#xff1a;工具欄的設置與操作XP中將…

Java基礎學習-Path環境變量的配置

1.為什么要進行Path環境變量的配置程序的編譯和執行需要使用到javac和java命令&#xff0c;所以只能在bin目錄下寫程序&#xff0c;而實際開發中&#xff0c;我們不可能將程序全部寫到bin目錄下&#xff0c;所以我們不許讓javac和java命令在任意目錄下都能夠被訪問。這時候&…

rails 共享變量_如何將Rails實例變量傳遞給Vue組件

rails 共享變量by Gareth Fuller由Gareth Fuller 如何將Rails實例變量傳遞給Vue組件 (How to pass Rails instance variables into Vue components) I’m currently working with a legacy Rails application. We are slowly transitioning the front-end from Rails views to…

Leetcode: Counting Bits

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1s in their binary representation and return them as an array.Example: For num 5 you should return [0,1,1,2,1,2].Follow up:It is very easy to c…

第一個python爬蟲_Python爬蟲01——第一個小爬蟲

Python小爬蟲——貼吧圖片的爬取 在對Python有了一定的基礎學習后&#xff0c;進行貼吧圖片抓取小程序的編寫。 目標&#xff1a; 首先肯定要實現圖片抓取這個基本功能 然后實現對用戶所給的鏈接進行抓取 最后要有一定的交互&#xff0c;程序不能太傻吧 一、頁面獲取 要讓pytho…

Mac下,如何把項目托管到Github上(Github Desktop的使用)

在上一篇中&#xff0c;詳細講解了使用X-code和終端配合上傳代碼的方法&#xff0c;這種方法比較傳統&#xff0c;中間會有坑&#xff0c;英文看起來也費勁&#xff0c;不過Github官方提供了一個Mac版的客戶端&#xff0c;如下圖&#xff1a; 附上下載鏈接&#xff1a;傳送門 下…

計算機網絡英文面試題,計算機網絡面試題整理

GET和POST的區別&#xff1f;GET和POST方法沒有實質上區別&#xff0c;只是報文格式不同。GET和POST是HTTP協議中的兩種請求方法。而 HTTP 協議是基于 TCP/IP 的應用層協議&#xff0c;無論 GET 還是 POST&#xff0c;用的都是同一個傳輸層協議&#xff0c;所以在傳輸上&#x…

利用遞歸求某數的階乘——C/C++

#include<stdio.h>int getFactorial(int n) {if(n0)return 1;else return n*getFactorial(n-1); }int main() {int n,res;scanf("%d",&n);res getFactorial(n);printf("%d",res);return 0; } 轉載于:https://www.cnblogs.com/daemon94011/p/106…

intern_充分利用Outreachy Intern申請流程

internby Joannah Nanjekye喬安娜南耶基(Joannah Nanjekye) 充分利用Outreachy Intern申請流程 (Get the most out of your Outreachy Intern application process) Outreachy gives three-month paid internships for persons that are underrepresented in tech. Interns ar…

Put-Me-Down項目Postmortem2

一.設想和目標二.計劃三.資源四.變更管理五.設計/實現六.測試/發布總結一.設想和目標 1. 我們的軟件要解決什么問題&#xff1f;是否定義得很清楚&#xff1f;是否對典型用戶和典型場景有清晰的描述&#xff1f; 我們的軟件要幫助低頭族控制使用手機時間。功能很明確&#xff0…

大數據實驗報告總結體會_建設大數據中臺架構思考與總結

簡介本文介紹完善的大數據中臺架構了解這些架構里每個部分的位置&#xff0c;功能和含義及背后原理及應用場景。幫助技術與產品經理對大數據技術體系有個全面的了解。數據中臺定義&#xff1a;集成離線數倉與實時數倉&#xff0c;并以多數據源統一整合采集到kafka,再通過kafka進…

半數集問題

給定一個自然數n&#xff0c;由n開始可以依次產生半數集set(n)中的數如下&#xff1a; (1) n ∈set(n)&#xff1b; (2) 在n的左邊加上一個自然數&#xff0c;但該自然數不能超過最近添加的數的一半&#xff1b; (3) 按此規則進行處理&#xff0c;直到不能再添加自然數為止。…

微型計算機控制理論基礎答案,微型計算機控制技術試卷c

微型計算機控制技術試卷a潘新民 微型計算機控制技術實用教程微型計算機控制技術試卷C一、選擇題(本題共10小題&#xff0c;每小題 1.5分&#xff0c;共15分)1. DAC0832的VREF接-5V&#xff0c;IOUT1接運算放大器異名端&#xff0c;輸入為1000000B &#xff0c;輸出為( )。A. 5V…

aws lambda_四處奔走:初學者遇到AWS Lambda

aws lambdaby Janaka Bandara通過Janaka Bandara 四處奔走&#xff1a;初學者遇到AWS Lambda (Running around the block: a beginner meets AWS Lambda) Computing! It sure has a very long, vivid (and sometimes awkward) history. Some key milestones include:計算&…

python打開快捷方式_Python創建啟動目錄的快捷方式,python,到

# -*- coding:utf-8 -*-# author&#xff1a;lizonezhiimport osimport sysimport pythoncomimport win32com.client as clientdef createShortCut(filename): # 目前創建的無起始位置"""filename should be abspath, or there will be some strange errors&quo…

二叉樹的基本操作及應用(三)

#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> typedef char DataType; int depth0; int h11; int nlayer1; char ch2; typedef struct node {DataType data;//節點數據元素struct node *lchild;//指向左孩子struc…

maven的profile詳解

詳細內容請見&#xff1a;https://www.cnblogs.com/wxgblogs/p/6696229.html Profile能讓你為一個特殊的環境自定義一個特殊的構建&#xff1b;profile使得不同環境間構建的可移植性成為可能。Maven中的profile是一組可選的配置&#xff0c;可以用來設置或者覆蓋配置默認值。有…

夏至未至計算機版音樂,夏至未至有哪些插曲背景音樂 夏至未至所有bgm歌曲匯總...

夏至未至有哪些插曲背景音樂 夏至未至所有bgm歌曲匯總夏至未至第一集插曲是什么?夏至未至插曲曝光。夏至未至是由陳學冬、鄭爽、白敬亭等聯袂主演的青春偶像劇,昨晚已經開播了&#xff0c;那么第一集的插曲是什么呢?和小編一起去看看吧!夏至未至第一集插曲《那些花兒》那片笑…