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

这份代码我在zju上ac了, 可这里判定是wa

Posted by navyakula at 2006-02-03 08:12:04 on Problem 1065
最坏的情况是我在侥幸在zju上过关了,否则, 还会有什么原因呢?
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#define MAXN 5001
struct Stick {
	int l, w;	
}a[MAXN];
int n;
int cmp( const void * a, const void * b)
{
	return ((const Stick *)a)->l - ((const Stick *)b)->l;	
}
int d[MAXN];
// longest increasing subsequence
int lis() 
{
	int seg = 0; 
	int max, sec;
	for(int i=1; i<=n; ++i)
	{
		max = -1;
		for(int j=0; j<seg; ++j) if( a[i].w >= d[j] && max < d[j] ) { max = d[j]; sec = j; }
		if( max == -1 ) d[seg++] = a[i].w;
		else d[sec] = a[i].w;
	}
	return seg;
}

int main()
{
	int t; scanf("%d", &t);
	while( t-- )
	{
		scanf("%d", &n);
		for(int i=1; i<=n; ++i) scanf("%d%d", &a[i].l, &a[i].w);
		qsort( &a[1], n, sizeof(Stick), cmp );
		printf( "%d\n", lis() );
	}
	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