Codeforces Beta Round #5 E. Bindian Signalizing
来源:互联网 发布:在淘宝上买苹果6可靠吗 编辑:程序博客网 时间:2024/05/29 19:02
题目大意
有N座山组成一个环,两座山互相能看到的要求是相连的圆弧上没有任何其他的山高度比它们高。求能看到的山的组数。
解题思路
首先要拆环成链,将山的序列改变,第一座山是最高的山。
其次是统计对于这个序列的L数组和R数组。表示:
- First hill to the left of the x, which is strictly higher than x.
- First hill to the right of the x, which is strictly higher than x.
生成C数组:
- All hills that are as high as x and are located between x and y.
(来自官方题解)
最后统计答案。
题目代码
#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <cctype>#include <algorithm>#include <time.h>#define eps 1e-10#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr<<1#define rc m + 1,r,tr<<1|1#define zero(a) fabs(a)<eps#define iabs(x) ((x) > 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )using namespace std;const int N = 1000005;int num[N],l[N],r[N],c[N],temp[N];int main(){ int n,max1=-1,p=-1; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&temp[i]); if(max1<temp[i]) { max1=temp[i]; p=i; } } num[n]=temp[p]; for(int i=0; i<n; i++) { num[i]=temp[p++]; p%=n; //cout<<num[i]<<" "; } for(int i=1;i<n;i++) { l[i]=i-1; while(l[i]>0&&num[i]>=num[l[i]]) { l[i]=l[l[i]]; } } c[n]=0; for(int i=n-1;i>=0;i--) { r[i]=i+1; while(r[i]<n&&num[i]>num[r[i]])r[i]=r[r[i]]; if(r[i]<n&&num[i]==num[r[i]]) { c[i]=c[r[i]]+1; r[i]=r[r[i]]; } } long long ans=0; for(int i=1;i<n;i++) { ans+=c[i]; ans+=2; if(l[i]==0&&r[i]==n)ans--; } cout<<ans; return 0;}
0 1
- Codeforces Beta Round #5 E. Bindian Signalizing
- 2017京东笔试编程题-保卫方案 | Codeforces Beta Round #5 E.Bindian Signalizing
- codeforces 5E Bindian Signalizing
- Codeforces 5E Bindian Signalizing
- Codeforces 5E. Bindian Signalizing
- codeforces 5E Bindian Signalizing
- Codeforces E.Bindian Signalizing
- Codeforces 5E Bindian Signalizing 题解
- codeforces 5.E. Bindian Signalizing
- CF 5 E. Bindian Signalizing
- Codeforces Beta Round #5 E
- E. Bindian Signalizing (拆环成链)(好题)
- CF5E Bindian Signalizing
- Codeforces5E - Bindian Signalizing
- Codeforces Beta Round #5
- Codeforces Beta Round #5
- Codeforces Beta Round #5
- Codeforces Beta Round #5
- 对象存储学习小结
- UVa 506 - System Dependencies
- POJ 2406 Power Strings(KMP)
- 枚举解Feed Ratios
- UVA 10003 Cutting Sticks
- Codeforces Beta Round #5 E. Bindian Signalizing
- iOS 报错 setValue:forUndefinedKey:]: this class is not key value coding
- poj 1068
- 接口
- HDU 1087 Super Jumping! Jumping! Jumping!
- 一切成功源于积累——20150217 欧美 美加 涨无穷 跌无尽
- CUDA Cuts: Fast Graph Cuts on the GPU
- Python模拟浏览器登录淘宝
- c++面向对象的设计思想总结