http://poj.org/problem?id=3250

题意 :  n个牛排成一列向右看,牛 i 能看到牛 j 的头顶,当且仅当牛 j 在牛 i 的右边并且牛 i 与牛 j 之间的所有牛均比牛 i 矮。 设牛 i 能看到的牛数为ni,求ni的和。

思路 : 表示一开始就想用数组去操作,结果说是会超时,问了别人的才知道原来要用栈啊,用栈保存,新的元素若是比栈顶元素大,就把栈里小于新元素的弹出栈

#include<cstdio>
#include<cstring>
#include<stack>
#include<iostream>
using namespace std ;
int main()
{
int n ;
scanf("%d",&n) ;
stack<long long>Q;
long long cnt = ;
int a;
scanf("%d",&a) ;
Q.push(a) ;
for(int i = ; i < n ; i++)
{
scanf("%d",&a) ;
while(!Q.empty()&&a>=Q.top())
{
Q.pop();
}
cnt += Q.size();
Q.push(a) ;
}
printf("%lld\n",cnt) ;
return ;
}

POJ3250Bad Hair Day的更多相关文章

  1. poj--3250--Bad Hair Day(模拟)

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit ...

随机推荐

  1. 30个惊人的插件来扩展 Twitter Bootstrap

    Bootstrap Maxlength It is a lightweight plugin that allows detecting the HTML maxlength property of ...

  2. WPF 绑定五(本身就是数据源)

    xaml: <Window x:Class="WpfApplication1.Window5" xmlns="http://schemas.microsoft.co ...

  3. Sending Email from mailx Command in Linux Using Gmail’s SMTP

    The mailx or mail command in Linux is still providing service for guys like me, especially when we n ...

  4. 演出排期JavaScript

    <script language="JavaScript" type="text/javascript"> var diarydays=" ...

  5. ActiveMQ之Topic

    与Queue不同,Topic实现的是发布/订阅模型,在下面的例子中,启动两个消费者共同监听一个Topic,然后循环给这个Topic发送多个消息. 例子: public class TopicTest ...

  6. Java从入门到精通——数据库篇Oracle 11g服务详解

    装上Oracle之后大家都会感觉到我们的电脑慢了下来,如何提高计算机的速度呢?我们应该打开必要的服务,关闭没有用的服务.下面是Oracle服务的详解: Oracle ORCL VSS Writer S ...

  7. Java String.split()注意点

    //String[] aa = "aaa|bbb|ccc".split("|");//错误 String[] aa = "aaa|bbb|ccc&qu ...

  8. 【转载】MySQL innodb_table_stats表不存在的解决方法

    MySQL 版本 5.6.14 公司有几台MySQL服务器的错误日志显示,有几个系统表不存在.innodb_table_statsinnodb_index_statsslave_master_info ...

  9. iOS的动画效果类型及实现方法

    实现iOS漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransit ...

  10. google api , using a refresh token to get the access token

    router.get('/refresh',function(req,res){ oauth2Client.credentials = { refresh_token: '1/RqVyL7yLBxws ...