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 hujiafeng at 2008-07-12 09:55:28 on Problem 3636
#include<iostream>
#include<algorithm>
using namespace std;
struct Node{
	int x,y;
}a[20001];
int com(Node a,Node b)  //比较函数 
{
	return a.x>b.x||((a.x==b.x)&&a.y<=b.y);
}
int n;
int d[20001],f[20001];//F[i]表示从1到i这一段中以i结尾的最长上升子序列的长度 
int find(int x,int len)
{
    for(int i=len;i>=1;i--)
    if(d[i]>=x&&d[i-1]<x) return i;
}    
int search()
{
	int i,j,k;
	memset(f,0,sizeof(f));
	d[0]=0;
	int len=0;
	for(i=1;i<=n;i++)
	{
		if(a[i].y>=d[len])
		{
			len++;
			d[len]=a[i].y;
		}
		if(a[i].y<d[len])
		{
			j=find(a[i].y,len);  //在d[]中找大于等于a[i]的第一个数 
			d[j]=a[i].y;
		}
	}
	return len;
}		
int main()
{
	int i,t;
	scanf("%d",&t); 
	while(t--)
	{
		int count=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
		sort(a+1,a+n+1,com);
	//	for(i=1;i<=n;i++)
	//	cout<<a[i].y<<" "; 
        printf("%d\n",search());
	}
	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