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

first dp 超时 最后水过

Posted by qqgyp at 2011-05-19 16:29:35 on Problem 3671
#include <iostream>
using namespace std;

int a[30002];
int b[30002];

int main()
{
	int n;
	cin>>n;
	int i,j;
	int change;
	for(i=0;i<n;i++)
		cin>>a[i];
	b[0] = a[0];
	j=0;
	if(b[0]==1)change = -1;
	else change=0;
	for(i=1;i<n;i++)
	{
		if(a[i]==2)
		{
			b[++j]=a[i];
			if(change==-1)
				change = j;
		}
		else if(a[i]==1&&change==-1)b[++j]=a[i];
		else 
		{
			b[change]=a[i];
			change++;
			if(change>j)
				change = -1;
		}
	}
	cout<<n-j-1<<endl;
}

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