poj--3250--Bad Hair Day(模拟)
| Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.
Each cow i has a specified height hi (1 ≤ hi
≤ 1,000,000,000) and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cow
i can see the tops of the heads of cows in front of her (namely cows
i+1, i+2, and so on), for as long as these cows are strictly shorter than cow
i.
Consider this example:
=
= =
= - = Cows facing right -->
= = =
= - = = =
= = = = = =
1 2 3 4 5 6
Cow#1 can see the hairstyle of cows #2, 3, 4
Cow#2 can see no cow's hairstyle
Cow#3 can see the hairstyle of cow #4
Cow#4 can see no cow's hairstyle
Cow#5 can see the hairstyle of cow 6
Cow#6 can see no cows at all!
Let ci denote the number of cows whose hairstyle is visible from cow
i; please compute the sum of c1 through cN.For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.
Input
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow
i.
Output
cN.
Sample Input
6
10
3
7
4
12
2
Sample Output
5
Source
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[101000];
int main()
{
int n;
while(scanf("%d",&n)!= EOF)
{
int top = 0;
long long ans = 0;
for(int i = 0; i < n; i++)
{
int h;
scanf("%d",&h);
//保证严格单调递减的序列
while(top > 0 && num[top] <= h)
--top;
ans += top;//记录每一个下标和
num[++top] = h;
}
printf("%lld\n",ans);
}
return 0;
}
poj--3250--Bad Hair Day(模拟)的更多相关文章
- Poj 3250 单调栈
1.Poj 3250 Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...
- poj 3250 Bad Hair Day(栈的运用)
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1027 The Same Game(模拟)
题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...
- poj 3250 Bad Hair Day (单调栈)
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 3250 Bad Hair Day(单调队列)
题目链接:http://poj.org/problem?id=3250 思路分析:题目要求求每头牛看见的牛的数量之和,即求每头牛被看见的次数和:现在要求如何求出每头牛被看见的次数? 考虑到对于某头特定 ...
- (单调队列) Bad Hair Day -- POJ -- 3250
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
随机推荐
- idea 中web项目 用自带tomcat启动问题,
严重: Exception sending context initialized event to listener instance of class com.zenointel.logserve ...
- js 回调函数小例子
js 回调函数小例子 <script> //将函数作为另一个函数的参数 function test1(){ alert("我是test1"); } function t ...
- 杂项-DB-分布式:HBase
ylbtech-杂项-DB-分布式:HBase HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系 ...
- luogu 3952 时间复杂度(模拟)
时间复杂度 这道题从两个月前开始做,一直没做出来,最后今晚决心一定要做出来.于是开始认真的在打草纸上写思路,最后在AC的那一刻,差点哭了出来!! 题目大意 这个自己看吧,noip2017的D1T2 s ...
- C#比较二个数组并找出相同或不同元素的方法
这篇文章主要介绍了C#比较二个数组并找出相同或不同元素的方法,涉及C#针对数组的交集.补集等集合操作相关技巧,非常简单实用, 具有一定参考借鉴价值,需要的朋友可以参考下 " }; " ...
- gcc编译c中有与lua交互的代码
编译C程序中有与Lua有关的程序(编译环境是Linux系统,lua解释器是luajit)gcc -o test30 test30.cpp -I/usr/local/include/luajit-2.0 ...
- 路飞学城Python-Day50
05-运算符 常用运算符 算数运算符 赋值运算符 比较运算符 逻辑运算符 // 赋值运算符 var money = prompt('请输入金额'); ...
- P3376 【模板】网络最大流(luogu)
P3376 [模板]网络最大流(luogu) 最大流的dinic算法模板(采取了多种优化) 优化 时间 inline+当前弧+炸点+多路增广 174ms no 当前弧 175ms no 炸点 249 ...
- kvm三个kernel相关的调优
今天在杭州参加淘宝嘉年华技术沙龙,主题是虚拟化和云计算,三个讲演: 淘宝网子团分享淘宝kvm技术的使用 华为的杨晓伟介绍虚拟化技术 阿里云郑永升介绍弹性云计算技术 其中KVM 调优,三点值得关注的: ...
- IOS - PDF合并
#pragma mark - Merge PDF - (void)mergePDF { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSD ...