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

为什么一个AC一个WA啊?!!!

Posted by wsj19911101 at 2011-02-14 16:20:42 on Problem 1609
先放AC的~~
#include<cstdio>
#include<algorithm>
struct t{
	int l;
	int m;
}a[10000];
int cmp(const void*a,const void*b)
{
	if(((t*)a)->l-((t*)b)->l)return ((t*)a)->l-((t*)b)->l;
	else return ((t*)a)->m-((t*)b)->m;
}
int n,max[10000],x,i,j;
int main()
{
	while(scanf("%d",&n)&&n){
		max[0]=1;
		for(i=0;i<n;i++)scanf("%d%d",&a[i].l,&a[i].m);
		qsort(a,n,sizeof(t),cmp);
		for(i=1;i<n;i++){
			x=0;
			for(j=0;j<i;j++)if(a[i].m>=a[j].m&&x<max[j])x=max[j];
			max[i]=x+1;
		}
		x=0;
		for(i=0;i<n;i++)if(max[i]>x)x=max[i];
		printf("%d\n",x);
	}
	printf("*\n");
}


再放哇的~~
#include<cstdio>
#include<algorithm>
struct t{
	int l;
	int m;
}a[10000];
int cmp(const void*a,const void*b)
{
	return ((t*)a)->l-((t*)b)->l;
}
int n,max[10000],x,i,j;
int main()
{
	while(scanf("%d",&n)&&n){
		max[0]=1;
		for(i=0;i<n;i++)scanf("%d%d",&a[i].l,&a[i].m);
		qsort(a,n,sizeof(t),cmp);
		for(i=1;i<n;i++){
			x=0;
			for(j=0;j<i;j++)if(a[i].m>=a[j].m&&x<max[j])x=max[j];
			max[i]=x+1;
		}
		x=0;
		for(i=0;i<n;i++)if(max[i]>x)x=max[i];
		printf("%d\n",x);
	}
	printf("*\n");
}


只是排序函数上改了下,应该一样才对啊?为神马呢?求各位大大解释~~  —。— 谢谢了哦!

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