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

为什么总是runtime error啊?求大神指点下啊,代码如下

Posted by strikefreedom at 2012-11-16 00:17:38 on Problem 1065
#include <stdio.h>
#include <stdlib.h>

//const int NO=5000;
#define NO 5000

struct node
{
	int l,w,flag;
}wooden[NO];

int compare(const void *a,const void *b)
{
	struct node *c=(struct node *)a;
	struct node *d=(struct node *)b;
	if (c->l!=d->l)
		return c->l>d->l;
	else 
		return c->w>d->w;
}

int main()
{
	int i,j,k,l,l1,n,m,sum,flag1=0;
	freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d",&m);
		for (j=0;j<m;j++)
		{
			scanf("%d%d",&wooden[j].l,&wooden[j].w);
			wooden[j].flag=0;
		}
		qsort(wooden,m,sizeof(wooden[0]),compare);
		k=l=sum=0;
		l1=m-1;
		for (j=0;j<m;j++)
		{
			if (wooden[j].flag==1)
				continue;
			wooden[j].flag=1;
			sum++;
			for (k=j+1;k<m;k++)
			{
				if (wooden[k].flag==0 && (wooden[k].w>=wooden[j].w))
					wooden[k].flag=1;
			}
		}
		printf("%d\n",sum);
	}	
	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