(单调队列) Bad Hair Day -- POJ -- 3250
http://poj.org/problem?id=3250
Bad Hair Day
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: = Cow#1 can see the hairstyle of cows #2, 3, 4 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 Line 1: The number of cows, N.
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i. Output Line 1: A single integer that is the sum of c1 through cN.
Sample Input 6 Sample Output 5 Source |
#include<stdio.h>
#define N 80010 int Stack[N]; int main()
{
int top = , i, n, p;
__int64 sum = ; scanf("%d", &n); for(i=; i<=n; i++)
{
scanf("%d", &p);
while(top> && Stack[top]<=p)
top--;
sum += top;
Stack[++top] = p;
} printf("%I64d\n", sum);
return ;
}
(单调队列) Bad Hair Day -- POJ -- 3250的更多相关文章
- POJ 2823 Sliding Window + 单调队列
一.概念介绍 1. 双端队列 双端队列是一种线性表,是一种特殊的队列,遵守先进先出的原则.双端队列支持以下4种操作: (1) 从队首删除 (2) 从队尾删除 (3) 从队尾插入 (4) ...
- Poj 3250 单调栈
1.Poj 3250 Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...
- POJ 2838 单调队列
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 55309 Accepted: 15911 ...
- poj 2823 Sliding Window (单调队列入门)
/***************************************************************** 题目: Sliding Window(poj 2823) 链接: ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
- poj 1821 Fence 单调队列优化dp
/* poj 1821 n*n*m 暴力*/ #include<iostream> #include<cstdio> #include<cstring> #incl ...
- POJ 2823 Sliding Window 【单调队列】
题目链接:http://poj.org/problem?id=2823 题目大意:给出一组数,一个固定大小的窗体在这个数组上滑动,要求出每次滑动该窗体内的最大值和最小值. 这就是典型的单调队列,单调队 ...
- 【POJ 2823】Sliding Window(单调队列/堆)
BUPT2017 wintertraining(16) #5 D POJ - 2823 题意 给定n,k,求滑窗[i,i+k-1]在(1<=i<=n)的最大值最小值. 题解 单调队列或堆. ...
- POJ 3162 Walking Race(树形dp+单调队列 or 线段树)
http://poj.org/problem?id=3162 题意:一棵n个节点的树.有一个屌丝爱跑步,跑n天,第i天从第i个节点开始跑步,每次跑到距第i个节点最远的那个节点(产生了n个距离),现在要 ...
- caioj 1172 poj 2823 单调队列过渡题
给定一个n个数的数列,从左至右输出每个长度为m的数列段内的最大数. 输入:第一行两个整数n和m( 1<= n <= 20 0000,m<=n).下来给出n个整数. 输出:一行一个整数 ...
随机推荐
- js原生语法实现表格操作
HTML页面: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- c#devexpress GridContorl datasource为 类字段的实现方式 非datatable方式以及其他操作总结
1:定义model class A { public string a{get;set;} public string b{get;set;} } 2:赋值: A aobj=new A(); aobj ...
- Informatica_(5)高级应用
五.高级应用21.任务分区 分区是通过并行处理来提供PowerCenter的执行效率. 分区类型包括:Database partitioning.Hash Auto-keys.Hash User-ke ...
- Android——Activity跳转
Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayou ...
- dpdk优化相关 转
注:本文是参照了一些其他文章,原文地址点击这里. 首先根据这篇文章进行了性能瓶颈的分析 策略与方法 首先根据木桶原理,首先要找到最弱的地方,怎么找往上看↑. 想能优化需要考虑如下: 优化BIOS设置 ...
- (O)JS:执行环境、变量对象、活动对象和作用域链(原创)
var a=1; function b(x){ var c=2; console.log(x); } b(3); ·执行环境(execution context),也称为环境.执行上下文.上下文环境. ...
- nodejs TLS 只加密,未授权,进一步完善
const tls = require('tls'); const fs = require('fs'); const options = { key: fs.readFileSync('my_key ...
- Python 中docx转pdf
#第一种import comtypes.clientdef convertDocxToPDF(infile,outfile): wdFormatPDF = 17 word = comtypes.cli ...
- [ ZooKeeper]ZooKeeper 的功能和原理
Zookeeper功能简介: ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现.分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅 ...
- go语言练习
// main package main import ( "fmt" "runtime" "sync" ) func main() { f ...