| ||||||||||
| 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 <cstring>
#include <cstdio>
int N,ma,pos1,pos2;//pos1记录上个1的位置,pos2记录2的位置
int a[30007],f[30007];
int max(int a,int b)
{
return a>b ? a:b;
}
int main()
{
scanf("%d",&N);
for(int i=1;i<=N;i++)
scanf("%d",&a[i]);
pos1=pos2=0;
for(int i=1;i<=N;i++)
{
if(a[i]==1)
{
f[i]=f[pos1]+=1;
pos1=i;
}
if(a[i]==2)
{
f[i]=max(f[pos1],f[pos2])+1;
pos2=i;
}
}
ma=max(f[pos1],f[pos2]);
printf("%d\n",N-ma);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator