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 hheq121 at 2008-08-15 09:47:21 on Problem 1328
#include<iostream>
#include<math.h>
using namespace std;
int n,d;
void myswap(double a[],double b[]);
void Qsort(double p[][4],int low ,int high);
int part(double p[][4],int low ,int high);
int main()
{
//	freopen("1328.txt","r",stdin);
	int i,j;
	for(int t=1;;t++)
	{	
		int num=1;
		scanf("%d%d",&n,&d);
		if(n==0&&d==0)
			break;
		
		double p[1005][4];
		for(i=0;i<1005;i++)
			for(j=0;j<4;j++)
				p[i][j]=0;
		int fin=1;
		for(i=1;i<=n;i++)
		{
			scanf("%f%f",&p[i][0],&p[i][1]);
			if(d<=0||p[i][1]-d>0||p[i][1]+d<0)
			{
				fin=0;			
			}
			double temp=sqrt(d*d-p[i][1]*p[i][1]);
			p[i][2]=p[i][0]-temp;
			p[i][3]=p[i][0]+temp;
		}
		if(fin==0)
		{
			printf("Case %d: %d\n",t,-1);
				continue ;
		}
		//按p[2]快速排序
//---------------------------------------------
		Qsort(p,1,n);
/*		for(i=1;i<n;i++)
		{
			for(j=0;j<4;j++)
				printf("%f     ",p[i][j]);
			printf("\n");
		}
*/
//---------------------------------------------		
		for(i=1;i<=n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				if(p[i][3]<p[j][2])
				{
					num++;
					i=j;
					break;
				}
			}
		}
		
		printf("Case %d: %d\n",t,num);

	}
	getchar();
	return 0;
}

int part(double p[][4],int low ,int high)
{
	double piv=p[low][2];
	while(low<high)
	{
		while(low<high&&p[high][2]>=piv)
			high--;
		myswap(p[low],p[high]);
		while(low<high&&p[low][2]<=piv)
			low++;
		myswap(p[low],p[high]);
	}
	return low;
}
void Qsort(double p[][4],int low,int high)
{
	if(low<high)
	{
		int  piv=part(p,low,high);
		Qsort(p,low,piv-1);
		Qsort(p,piv+1,high);
	}
}
void myswap(double a[],double b[])
{
	double temp=a[0];
	a[0]=b[0];
	b[0]=temp;
	
	temp=a[1];
	a[1]=b[1];
	b[1]=temp;
	
	temp=a[2];
	a[2]=b[2];
	b[2]=temp;
	
	temp=a[3];
	a[3]=b[3];
	b[3]=temp;
}

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