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

跪求测试用例····

Posted by suranxu007 at 2008-07-29 10:57:55 on Problem 1328
两天了... ... 还是WA啊~
为什么啊~~

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

#define MX 100000

double L[MX]; // left end point
double R[MX]; // right end point
int indexs[MX];  //indexes of the order

bool change(double &L,double &R,int d)
{
	// currently: L is x, R is y
	double x=L;
	double y=R;
	if(y>d)
		return false;
	double halfL=sqrt((double)(d*d-R*R));
	
	// now it becomes what it should be
	L=x-halfL;
	R=x+halfL;
	return true;
}

void mySort(int number)
{
	if(number<1)
		return;

	for(int i=1;i<=number;i++)
	{
		double min=R[i];
		int p=i;
		for(int j=i+1;j<=number;j++)
		{
			if(R[j]<min)
			{
				min=R[j];
				p=j;
			}
		}
		if(p!=i)
		{
			int tmp=indexs[i];
			indexs[i]=indexs[p];
			indexs[p]=tmp;
		}
	}
	
}

int main()
{
	int i;
	vector<int> v;
	while(1)
	{
		int n,d; //number of islands and radius of radar
		cin>>n>>d;
		if(0==n&&0==d)
			break;
		if(0==n)
		{
			break;
			//v.push_back(0);
			//continue;
		}
		if(n<0)
		{
			v.push_back(-1);
			continue;
		}
		if(d<0)
		{
			for(i=1;i<=n;i++)
			{
				cin>>L[i]>>R[i]; //here L means x, R means y --which would be changed at function change()
			}
			v.push_back(-1);
			continue;
		}
		bool legal=true;
		for(i=1;i<=n;i++)
		{
			cin>>L[i]>>R[i]; //here L means x, R means y --which would be changed at function change()
			indexs[i]=i;
			if(R[i]<0)
				R[i]=-R[i];
			if(!change(L[i],R[i],d))
			{
				v.push_back(-1);
				legal=false;
				break;
			}
		}
		if(!legal)
			continue;

		mySort(n);

		double point=R[indexs[i]];
		int TotalNum=1;
		for(i=1;i<=n-1;i++)
		{
			if(L[indexs[i+1]]>point)
			{
				TotalNum++;
				point=R[indexs[i+1]];
			}
		}
		v.push_back(TotalNum);
	}

	for(i=0;i<v.size();i++)
	{
		cout<<"Case "<<i+1<<": "<<v[i]<<endl;
	}

	return 1;
}

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