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

为什么我的程序在g++ ac 在 c++ wa

Posted by guohao at 2008-05-10 02:17:17 on Problem 1836
程序如下
#include<iostream>
#include<cstdlib>
using namespace std;
const int N=1000;
double a[N];
int d1[N],d2[N];
inline int find(double key,double *c,int left,int right){//<key zui da zhi
	if(c[left]>=key)return -1;
	else if(left==right)return left;
	if(c[right]<key)return right;
	else return
		find(key,c,left,(right+left)/2)>find(key,c,(right+left)/2+1,right)?find(key,c,left,(right+left)/2):find(key,c,(right+left)/2+1,right);
	
}
void lcs1(double *a,int n){//nlogn
	int len=0;
	double d[N];
	//memset(d,0,sizeof(d));
	//memset(d1,0,sizeof(d1));
	d[0]=a[0];//len==chang-1==0
	d1[0]=1;//0--n bao n zui chang zi xu lie 
	for(int i=1;i<n;i++){		
		if(a[i]>d[len]){//ying wu ==
			len++;
			d[len]=a[i];			
		}
		else {
			int k=find(a[i],d,0,len);
			if(k!=-1)
				d[k+1]=a[i];
		}
		d1[i]=len+1;//xian shi zuida chang
		if(d[0]>a[i])d[0]=a[i];//NOTE!
	}
}
void lcs2(double *a,int n){//nlogn
	int len=0;
	double r2[N];
	//memset(d2,0,sizeof(d2));
	//memset(r2,0,sizeof(r2));
	r2[0]=a[n-1];
	d2[n-1]=1;//k--n-1 han duan dian zui chang zi xu lie
	for(int i=n-2;i>=0;i--){		
		if(a[i]>r2[len]){
			len++;
			r2[len]=a[i];			
		}
		else {
			int k=find(a[i],r2,0,len);
			if(k!=-1)
				r2[k+1]=a[i];
		}
		d2[i]=len+1;
		if(r2[0]>a[i])r2[0]=a[i];//NOTE!
	}
}
int lcs(double *a,int n){
	lcs1(a,n);
	lcs2(a,n);
	int max=0;
	if(d1[n-1]>max)max=d1[n-1];
	if(d2[0]>max)max=d2[0];
	for(int i=0;i<n;i++)
		if(d1[i]+d2[i+1]>max)
			max=d1[i]+d2[i+1];
	return n-max;
}
void Cin(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
		cin>>a[i];
	cout<<lcs(a,t)<<endl;
}
int main(){
	//freopen("a.in","r",stdin);
	Cin();
	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