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

测试了N组数据,都没问题,一提交就是运行时出错,晕的死!!!!哪位大虾有空找找茬呀??

Posted by soidnhp at 2009-09-02 10:49:55 on Problem 2376
#include<stdio.h>
#include<malloc.h>
int N;
int T;
int **c;
int main()
{
	void quicksort(int p,int r);
	int i;
	int locat;
	int LonEnd;
	int cout=0;
	scanf("%d%d",&N,&T);
	c=(int **)malloc(sizeof(int *)*N);
	for(i=0;i<N;i++)
	{
		c[i]=(int *)malloc(sizeof(int)*2);
		scanf("%d%d",&c[i][0],&c[i][1]);
	}
	quicksort(0,N-1);
	locat=0;
	i=0;
	while(i<N )
	{
		if(c[i][0]> locat+1)
		{
			printf("-1\n");
			break;
		}
		LonEnd=i;
		while(i<N-1 && c[++i][0]<=locat+1  )
		{
			if(c[i][1]>c[LonEnd][1])
				LonEnd=i;
		}
		locat=c[LonEnd][1];
		cout++;
		if(locat>=T)
		{	
			printf("%d",cout);
			break;	
		}
	}
	
}

void quicksort(int p,int r)
{
	int i=p,j=r+1;
	int k0,k1;
	int swap;
	if(p<r)
	{
		k0=c[p][0];
		k1=c[p][1];
		while(4)
		{
			while(c[++i][0] <k0);
			while(c[--j][0]>k0);
			if(i<j)
			{
				swap=c[i][0];
				c[i][0]=c[j][0];
				c[j][0]=swap;
				swap=c[i][1];
				c[i][1]=c[j][1];
				c[j][1]=swap;
			}
			else
				break;
		}
		c[p][0]=c[j][0];
		c[p][1]=c[j][1];
		c[j][0]=k0;
		c[j][1]=k1;
		quicksort(p,j-1);
		quicksort(j+1,r);
		
	}
	
}

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