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 ...
随机推荐
- 2014.08.04,读书,读书笔记-《Matlab概率与数理统计分析》-第1章 MATLAB的数据基础
第1章 MATLAB数据基础 虽然一直间或使用MATLAB,但从来没有系统的学习过,现在开始也不晚.先对几个重点或者平时忽略的要点做下笔记. %后的所有文字为注释,多条命令可以放在一行,但要用逗号或分 ...
- UESTC--1262--Memory(dfs)
Memory Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu SubmitStatus De ...
- 从极大似然估计的角度理解深度学习中loss函数
从极大似然估计的角度理解深度学习中loss函数 为了理解这一概念,首先回顾下最大似然估计的概念: 最大似然估计常用于利用已知的样本结果,反推最有可能导致这一结果产生的参数值,往往模型结果已经确定,用于 ...
- adplus 抓取dump
工具所在路径 C:\Program Files\Windows Kits\10\Debuggers\x64 cmd窗口切换目录倒adplus所在路径下,输入抓取命令.adplus -hang -p ...
- [转]数据库事务中的隔离级别和锁+spring Transactional注解
数据库事务中的隔离级别和锁 数据库事务在后端开发中占非常重要的地位,如何确保数据读取的正确性.安全性也是我们需要研究的问题.ACID首先总结一下数据库事务正确执行的四个要素(ACID): 原子性(At ...
- Oracle学习系类篇(三)
1. 存储过程 CREATE OR REPLACE PROCEDURE SP_NAME( PM_NAME [IN/OUT/IN OUT] PM_TYPE...) {AS} ...
- webpack配置的学习
1.把不需要打包的文件复制到打包后的文件夹里 2.通过 Plugin 把注入到 bundle.js 文件里的 CSS 提取到单独的文件中
- StatusBarUtils工具类
import android.app.Activity; import android.app.Dialog; import android.content.Context; import andro ...
- 关于C++程序运行程序是出现的this application has requested the runtime to terminate it in an unusual way. 异常分析
今天运行程序是出现了this application has requested the runtime to terminate it in an unusual way. 的异常报告,以前也经常 ...
- 路飞学城Python-Day37(practise)
#1.自行创建测试数据 create database homework; use homework; # 年级表->老师表->课程表->班级表->学生表->成绩表-&g ...