题意:给出一队牛的高度 , 牛所面对的方向相同, 当前牛只能看见前面比他矮的牛的头 , 如遇见比他高的中断(详见样例) 问所有牛所能见到的牛的头的总数量
思路:单调栈维护一个有序序列,从左到右依次把小于当前牛的高度的牛出栈,栈里所剩下的就是能看见当前牛的牛的数量。
#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
#define read(x) scanf("%lld",&x)
#define debug puts("^^^^^^^")
using namespace std;
const int maxn=1e5+5;
typedef long long LL;
struct node{
LL num;
LL next,pre,id;
};
LL n;
LL a[maxn];
LL sum[maxn];
int main() {
while(read(n) != EOF && n) {
stack<node> s;
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++) {
read(a[i]);
sum[i]=sum[i-1]+a[i];
}
node tmp;
tmp.num=a[1];
tmp.next=tmp.pre=1;
tmp.