hdu 4252 A Famous City
题意:
一张相片上的很多建筑相互遮住了,根据高低不同就在相片上把一座高楼的可见部分作为一个矩形,
并用数字描述其高度,若一张相片上的两个建筑群中间有空地,高度则为0;求最少有多少个建筑;
分析:
输入的0不是建筑,则输入的总个数减去0的个数就是最多可能有的建筑数;
再从第一个开始从前往后搜,若发现比它高的则继续搜,若发现比它低的则说明它是一个独立的建筑,
这时可以返回搜其它的;若与它相等,说明这时它们还没有出现比它们低的建筑,则视其为同一个建筑,
则ans减1;
#include<cstdio>
#include<cstring>
#define maxn 100001
using namespace std;
int n,a[maxn];
int main()
{
int cas=;
while(scanf("%d",&n)!=EOF)
{
int ans=n;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)
{
if(a[i]==)
ans--;
else
{
for(int j=i+;j<=n;j++)
{
if(a[j]<a[i])
break;
if(a[j]==a[i])
{
ans--;
break;
}
}
}
}
printf("Case %d: %d\n",++cas,ans); }
return ;
}
hdu 4252 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 5352 MZL's City (多重匹配)
题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...
- HDU 4849 Wow! Such City!陕西邀请赛C(最短路)
HDU 4849 Wow! Such City! 题目链接 题意:依照题目中的公式构造出临接矩阵后.求出1到2 - n最短路%M的最小值 思路:就依据题目中方法构造矩阵,然后写一个dijkstra,利 ...
- HDU-4252 A Famous City(单调栈)
最后更新于2019.1.23 A Famous City ?戳这里可以前往原题 Problem Description After Mr. B arrived in Warsaw, he was sh ...
- hdu 4255 A Famous Grid
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...
- HDU 4256 The Famous Clock
The Famous Clock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4253 Two Famous Companies
Two Famous Companies Time Limit: 15000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...
- HDU 4251 The Famous ICPC Team Again 主席树
The Famous ICPC Team Again Problem Description When Mr. B, Mr. G and Mr. M were preparing for the ...
- HDU 4294 A Famous Equation(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4249 题目大意:给一个a+b=c的表达式,但是a.b.c中部分位的数字丢失,并用?代替,问有多少种方案 ...
随机推荐
- ASP.net 验证码(C#) MVC
ASP.net 验证码(C#) MVC http://blog.163.com/xu_shuhao/blog/static/5257748720101022697309/ 网站添加验证码,主要为防止机 ...
- [css]邮件的写法
<style type="text/css"> /* Client-specific Styles */ #outlook a{paddin ...
- 数组越界保护与消息传递black机制
数组越界保护if(index.row <= [array count]) 发送消息[[NSNotificationCenter defaultCenter] postNotificati ...
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- DataGridView绑定数据库,取得的数据插入到DataGridView指定列(一)
实现: 点击button1,从数据库中获得数据,指定数据库的某列数据插入到DataGridView指定列 一.双击button1进入事件代码 private void button1_Click(ob ...
- MATLAB 函数
MATLAB函数大全 1.常见 http://wenku.baidu.com/link?url=tPpwD7Ox_1sG-SQv_XdYszBAPY9LX_Zb_dde_5JeOiu7RwN_i14X ...
- C++-什么时候需要在类的构造函数中使用初始化列表
1,如果基类没有default构造函数,则意味着其不能自己初始化.如果其被派生,派生类的构造函数要负责调用基类的构造函数,并传递给它需要的参数.下例中Base 2,如果类成员没有默认构造函数.下例中E ...
- Linux-Unix版本介绍
转自: http://blog.163.com/li_zhuangs/blog/static/195698098201182411360635/ < DOCTYPE html PUBLIC -W ...
- JSTL标准标签库
有时使用EL和标准动作达不到目的,于是就引入定制标记. 对于JSP页面创作人员来说,定制标记使用起来比脚本要容易一些.不过对于JAVA程序员来说,简历定制标记处理器反而更困难.幸运的是,已经有了一个标 ...
- Volatile vs VolatileRead/Write?
You should never use Thread.VolatileRead/Write(). It was a design mistake in .NET 1.1, it uses a ful ...