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

BZOJ 1113: [Poi2008]海报PLA相关推荐

  1. bzoj 1113: [Poi2008]海报PLA(栈)

    1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1272  Solved: 870 [Submit][Sta ...

  2. bzoj1113[Poi2008]海报PLA

    Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值 ...

  3. 【BZOJ-1113】海报PLA 单调栈

    1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 896  Solved: 573 [Submit][Stat ...

  4. BZOJ 1124: [POI2008]枪战Maf(构造 + 贪心)

    题意 有 \(n\) 个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开枪. 因此,对于不同的开枪顺序,最后死的人也不同. 问最 ...

  5. [BZOJ 1112] [POI2008] 砖块Klo 【区间K大】

    题目链接:BZOJ - 1112 题目分析 枚举每一个长度为k的连续区间,求出这个区间的最优答案,更新全局答案. 可以发现,这个区间的所有柱子最终都变成这k个数的中位数时最优,那么我们就需要查询这个区 ...

  6. bzoj 1124 [POI2008]枪战Maf 贪心

    [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 741  Solved: 295 [Submit][Status][Di ...

  7. bzoj 1116: [POI2008]CLO(并查集)

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1180  Solved: 649 [Submit][Statu ...

  8. bzoj 1124: [POI2008]枪战Maf(贪心)

    1124: [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 713  Solved: 278 [Submit][Stat ...

  9. bzoj 1121: [POI2008]激光发射器SZK

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 951  Solved: 791 [Submit][S ...

最新文章

  1. oracle 11g完全安装教程(CentOS)
  2. 2020暑期实习后台开发字节跳动笔试
  3. 汽车abs matlab仿真模糊pid控制
  4. 蓝桥杯 算法提高 日期计算
  5. c# mvvm模式获取当前窗口_AWTK-MVVM 介绍
  6. Python编程-继承和接口
  7. sqlserver2005安装(附加sqlserver2005 和 sqlserver2005 sp4补丁,完整安装包)
  8. python的cubes怎么使用_Python measure.marching_cubes方法代碼示例
  9. python爬虫爬取中央气象台每日天气图
  10. 用Excel制作条形码
  11. Windows搭建Nginx直播推流服务器
  12. css3 特效大全,CSS3 特效范例整理
  13. word使用Bibtex4word插入参考文献
  14. mysql启动与登录
  15. g4600支持服务器内存吗,Intel奔腾G4560和G4600哪个好?秒懂G4560和G4600区别 (全文)
  16. GUESS手表全新推出2022年农历新年系列
  17. Android-向手机模拟器添加图片
  18. 人力资源机器下载方法
  19. Window对象(1)
  20. datastage教程

热门文章

  1. java批量提取文件夹名称_bat 批量提取指定目录下的文件名
  2. pyqt开发的程序模板_小程序定制开发和模板开发要多少钱?有什么区别?
  3. c语言getch在哪个头文件,用getch()需要头文件吗?
  4. coreos 安装mysql_CoreOS 在 PC 上快速安装方法指南
  5. 操作符offset和seg
  6. Java Double类parseDouble()方法的示例
  7. mysql gtid binlog_MySQL之-四步实现BinLog Replication升级为GTIDs Replication的代码实例
  8. 递归-汉诺塔(代码、分析、汇编)
  9. 【操作系统】互斥:软件解决方法
  10. 【转载】最短路径之Dijkstra算法详细讲解