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 songruirui at 2013-03-12 20:18:22 on Problem 1836
#include <iostream>
#include <memory.h>
using namespace std;
int main()
{
	int firstround[1001];
	int secondround[1001];
	float heights[1001];
	int totalnum;
	cin>>totalnum;
	int i,j;
	for(i=1;i<=totalnum;i++)
	{	
		cin>>heights[i];
		firstround[i]=1;
		secondround[i]=1;
	}
	for(i=2;i<=totalnum;i++)
	{
		for(j=i-1;j>=1;j--)
		{
			if(heights[i]>heights[j]&&firstround[i]<firstround[j]+1)
				firstround[i]=firstround[j]+1;
			
		}
	}
	for(i=totalnum-1;i>=1;i--)
	{
		for(j=i+1;j<=totalnum;j++)
		{
			if(heights[i]>heights[j]&&secondround[i]<secondround[j]+1)
				secondround[i]=secondround[j]+1;
			
		}
	}
	int max=1;
	for(i=1;i<=totalnum;i++)
	{
		if(firstround[i]+secondround[i]>max)
		{
			max=firstround[i]+secondround[i];
			for(int k=i+1;k<=totalnum;k++)
			{
				if(heights[k]==heights[i]&&secondround[k]==secondround[i])
				{	
					max++;
				}
			}
		}
	}
	cout<<totalnum-max+1;
//	system("pause");


	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