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 |
一开始想着像查找最长升序列那样查找最长非递减序列,可是超时,后来想想就两个数,哈哈,简单思路过了,附代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator