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

huys why WA, plz somebody send me his solution;)

Posted by hasan83 at 2007-09-25 02:55:06 on Problem 1328
#include<iostream>
#include<cmath>
using namespace std;

struct island
{
	int x,y;
};

int compare(const void *p1,const void *p2)
{
	island n1=*(island *)p1,n2=*(island *)p2;
	if(n1.x>n2.x)return 1;
	if(n1.x==n2.x)
	{
		if(n1.y<n2.y)return 1;
		if(n1.y>n2.y)return -1;
		return 0;
	}
	if(n1.x<n2.x)return -1;
	return 0;
}

int main()
{
	int n,d,t=0;
	while(cin>>n>>d&&n+d!=0)
	{
		island a[1000];
		for(int i=0;i<n;i++)
		{
			cin>>a[i].x>>a[i].y;
		}
		qsort(a,n,sizeof(island),compare);
		int c=0,m=0;i=0;
		while(m<n)
		{
			c++;
			int x=a[i].x,y=a[i].y;
			if(y>d)break;
			m++;
			double px=double(x)+double(sqrt(d*d-y*y));
			for(int j=i+1;j<n;j++)
			{
				if(double(sqrt((px-a[j].x)*(px-a[j].x)+a[j].y*a[j].y))>double(d)){i=j;break;}
				m++;
			}
		}
		if(m<n)cout<<"Case "<<++t<<": "<<-1<<endl;
		else cout<<"Case "<<++t<<": "<<c<<endl;
	}

	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