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 sdlwwlp at 2011-07-11 10:12:50 on Problem 3671
#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:
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