POJ——T 3250 Bad Hair Day
http://poj.org/problem?id=3250
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 19619 | Accepted: 6702 |
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
Sample Input
6
10
3
7
4
12
2
Sample Output
5
Source
#include <algorithm>
#include <iostream>
#include <cstdio> using namespace std; #define LL long long
const int N();
LL Stack[N],top,ans; int main()
{
LL n; cin>>n;
for(LL h,i=;i<=n;i++)
{
cin>>h;
for(;top&&Stack[top]<=h;) top--;
ans+=top; Stack[++top]=h;
}
cout<<ans;
return ;
}
POJ——T 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 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 3250 Bad Hair Day(栈的运用)
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- POJ 3250 Bad Hair Day(单调栈)
[题目链接] http://poj.org/problem?id=3250 [题目大意] 有n头牛,每头牛都有一定的高度,他能看到在离他最近的比他高的牛前面的所有牛 现在每头牛往右看,问每头牛能看到的 ...
- POJ 3250 Bad Hair Day --单调栈(单调队列?)
维护一个单调栈,保持从大到小的顺序,每次加入一个元素都将其推到尽可能栈底,知道碰到一个比他大的,然后res+=tail,说明这个cow的头可以被前面tail个cow看到.如果中间出现一个超级高的,自然 ...
- poj 3250 栈应用
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #d ...
- poj 3250 Bad Hair Day【栈】
Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15922 Accepted: 5374 Des ...
随机推荐
- [USACO14FEB]路障Roadblock
题目:洛谷P2176. 题目大意:有n个点m条无向边,一个人要从1走到n,他会走最短路.现在可以让一条边的长度翻倍,求翻倍后这个人要多走多少距离. 解题思路:首先可以知道,翻倍肯定是在最短路上的某条边 ...
- 再谈CLR查找和加载程序集的方式
原文:再谈CLR查找和加载程序集的方式 这是一个老问题,以前也有朋友写过一些文章介绍,但可能还不是很全面.我也多次被人问到,这里结合案例再次谈谈,希望对大家有所帮助. 本文范例代码可以通过这里下载 h ...
- 题解 CF911D 【Inversion Counting】
这是一道看似复杂其实也不简单的思维题. 其实思路很明显. 因为这道题的数据范围比较大,有1e5的询问,如果暴力(像我考场上那样打平衡树)的话可以做到$mnlogn$. 但那样也是稳T. 经过思考之后我 ...
- cocos2dx 3.0 windows8下开发环境搭建搭建 不须要cygwin
已经接触cocos2dx有一段时间,但一直也仅仅是看看Demo,没有真正的去写代码.由于本人仅仅是java的coder.还是半路出家的coder,编程基础太浅. 对于c++.lua也不懂.近期coco ...
- ZOJ 1654 Place the Robots (二分匹配 )
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...
- iOS开发之软键盘使用小技巧
在iOS开发过程中,有时候须要弹出软键盘进行输入,有时候又须要在某些情况下隐藏软键盘,以提高用户体验. 今天有几个关于软键盘的小技巧和大家分享. (1)仅仅弹出数字键盘 有某些需求中,要求用户仅仅能在 ...
- vijos - P1176奇怪的数列 (递归 + 找规律)
P1176奇怪的数列 Accepted 标签:[显示标签] 背景 一天.学军数学小组的成员遇到了一个奇怪的数列,正巧信息小组的你碰到了他们. 于是他们把这个数列展示给你-- 描写叙述 这个数列是这种: ...
- [BZOJ4826][HNOI2017]影魔 可持久化线段树
链接 题意:给你 \(1\) 到 \(n\) 的排列 \(k_1,k_2,\dots,k_n\) ,对 \(i,j (i<j)\)来说,若不存在 \(k_s (i<s<j)\) 大于 ...
- Visual Studio Code Setup
Windows https://code.visualstudio.com/docs/setup/windows Additional Components and Tools https://cod ...
- jQuery插件开发初探
最简单的插件 $.fn.changeStyle = function (colorStr) { $(this).css('color',colorStr); } 应用如下: <!DOCTYPE ...