Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实很简单

Posted by yy17yy at 2011-07-01 17:16:50 on Problem 3298
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator