bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack> using namespace std; int main()
{
int n,cas=;
while(~scanf("%d",&n))
{
int i;
stack<int> stk;
stk.push(-);
int ans = ;
for(i=;i<n;i++)
{
int temp;
scanf("%d",&temp);
while(stk.top()>temp)
{
stk.pop();
}
if(stk.top()!=temp)
{
stk.push(temp);
if(temp!=) ans++;
}
}
while(!stk.empty()){stk.pop();}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}
bnuoj 25659 A Famous City (单调栈)的更多相关文章
- HDOJ 4252 A Famous City 单调栈
单调栈: 维护一个单调栈 A Famous City Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- HDU-4252 A Famous City(单调栈)
最后更新于2019.1.23 A Famous City ?戳这里可以前往原题 Problem Description After Mr. B arrived in Warsaw, he was sh ...
- 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- BZOJ 1628 [Usaco2007 Demo]City skyline:单调栈
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1628 题意: 题解: 单调栈. 单调性: 栈内元素高度递增. 一旦出现比栈顶小的元素,则表 ...
- 单调栈3_水到极致的题 HDOJ4252
A Famous City 题目大意 给出正视图 每一列为楼的高度 最少有几座楼 坑点 楼高度可以为0 代表没有楼 贡献了两发RE 原因 if(!s.empty()&&tem){s. ...
- Gym 100971D Laying Cables 单调栈
Description One-dimensional country has n cities, the i-th of which is located at the point xi and h ...
- BZOJ_1628_[Usaco2007_Demo]_City_skyline_(单调栈)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1628 给出\(n\)个距形的影子,问最少是多少个建筑的?(建筑的影子可以重叠). 分析 用单调 ...
- Code Forces Gym 100971D Laying Cables(单调栈)
D - Laying Cables Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- 小结:单调栈 & 单调队列
概要: 对于维护信息具有单调性的性质或者问题可以转化为具有单调性质的模型的题,我们可以考虑用单调栈或单调队列. 技巧及注意: 技巧很多,只要能将问题转化为单调性问题,就好解决了. 当维护固定长度的单调 ...
随机推荐
- Table of Contents - Ehcache
Ehcache 2.9.x API Developer Guide Key Classes and Methods Basic Caching Cache Usage Patterns Searchi ...
- js完美解决IE6不支持position:fixed的bug
详细内容请点击 <!DOCTYPE html><html><head><meta http-equiv="Content-Type" co ...
- HttpContext 讲解
HttpContext类:封装有关个别HTTP请求的所有HTTP特定的信息,又叫上下文.看到这个解释,我觉得有些抽象,Http特定信息具体又是什么?看了下备注:为继承 IHttpModule 和 IH ...
- asp.net(c#)网页跳转七种方法小结
在asp.net下,经常需要页面的跳转,下面是具体的几种方法.跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute se ...
- [老老实实学WCF] 第五篇 再探通信--ClientBase
老老实实学WCF 第五篇 再探通信--ClientBase 在上一篇中,我们抛开了服务引用和元数据交换,在客户端中手动添加了元数据代码,并利用通道工厂ChannelFactory<>类创 ...
- Cocos2d-x标签文乱码问题
我们在Windows下使用Visual Studio 2012开发游戏的时候,使用标签中包含中文时候会出现乱码或无法显示,如下图所示: 而应该显示的中文是如下图所示: HelloWorldScene. ...
- UI2_ScrollView&UIPageControl
// // ViewController.h // UI2_ScrollView&UIPageControl // // Created by zhangxueming on 15/7/10. ...
- UI4_UIToolBar
// // AppDelegate.m // UI4_UIToolBar // // Created by zhangxueming on 15/7/6. // Copyright (c) 2015年 ...
- 异常getaddrinfo enotfound
在看NodeJS开发指南这本书时,书中的一个例子,讲解http.request的.代码如下: var http = require('http'); var querystring = require ...
- 依赖映射 Dependent Mapping
让一个类为其子类(泛意上的)执行DB映射 一些对象肯定会出现在另一对象的上下文中. 此时,使用另一对象的Mapper来执行第一个对象的映射,来简化映射过程. 运行机制 在DB持久化时,依赖者类依赖于所 ...