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 1004115224 at 2012-08-09 09:56:42 on Problem 3671
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    int a;
    int b[30001];
    int ma[3];
    ma[1]=0;
    ma[2]=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==2)
        {
            b[i]=max(ma[1]+1,ma[2]+1);
            if(b[i]>ma[2])ma[2]=b[i];
        }
        else
        {
            b[i]=ma[1]+1;
            ma[1]++;
        }
    }
    cout<<n-max(ma[1],ma[2])<<endl;
    return 0;
}

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