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.mzph.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;那么第一集的插曲是什么呢?和小编一起去看看吧!夏至未至第一集插曲《那些花儿》那片笑…