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

牛人帮忙看看到底是什么地方出的错误啊??测试数据行,自己测试的所有数据也行,就是递交之后叫WA!

Posted by ang888 at 2010-05-30 19:15:13 on Problem 1836
//牛人帮忙看看到底是什么地方出的错误啊??测试数据行,自己测试的所有数据也行,就是递交之后叫WA!牛人帮忙看看啦!急死我了!  就是看不出来哪个地方出的错误。  难道是我那个边界问题没有考虑到??  源码如下:
#include<iostream>
#include<memory>
#include<algorithm>

using namespace std;

bool cmp(int a,int b)			//sort()排序的方法
{
	return a>=b;
}
float a[1050];
int main()
{
    memset(a,0,sizeof(a));
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
	int tmp=1;
	int dp[1050];
///////////////////////////////////////////////////////////////
	memset(dp,0,sizeof(dp)); 				//查找升序的最大值  max1
	dp[0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++)
		{
			if(a[i]>=a[j]) {
				dp[i]=dp[j]+1;
				tmp=tmp>dp[i]?tmp:dp[i];
			}
		}
		dp[i]=tmp;
		tmp=1;
	}
	sort(dp,dp+n,cmp);
	int max1=dp[0];
////////////////////////////////////////////////////
    memset(dp,0,sizeof(dp));				//查找降序的最大值  max2
	dp[0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++)
		{
			if(a[i]<=a[j]) {
				dp[i]=dp[j]+1;
				tmp=tmp>dp[i]?tmp:dp[i];
			}
		}
		dp[i]=tmp;
		tmp=1;
	}
	sort(dp,dp+n,cmp);
	int max2=dp[0];
/////////////////////////////////////////////////////
    int max;
	max=max1>max2?max1:max2; 				//比较max1和max2的值的大小,取最大值
	cout<<n-max<<endl;						//输出最后答案
	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