Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其实很简单In Reply To:dp+两个线段树1000+ms水过了。。。求更快的解法。。。 Posted by:huxinjie at 2011-05-26 10:46:35 把数组抽象成二维图形,,,相邻的点连线,,,数组就是一条折线,,, 数一下折线上凸的点的个数,,,ans=num*2 如果最后一个点也是上凸的点,,,ans-- for(scanf("%d",&tt);tt--;) { int n; scanf("%d",&n); int i,ans=0; for(i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=a[n+1]=-(1<<29); for(i=1;i<=n;i++) { if(a[i]>a[i-1]&&a[i]>a[i+1]) ans++,i++; } ans*=2; if(a[n]>a[n-1]) ans--; printf("%d\n",ans); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator