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。非常感谢O(∩_∩)O~

Posted by vigg at 2013-05-14 11:53:18
#include <IOSTREAM>
#include <MATH.H>
using namespace std;

#define DataType float


typedef struct 
{
	DataType x;
	DataType y;

}Coordinate;

typedef struct 
{
	DataType x1;
	DataType x2;
}Radar_x;

Coordinate Islands[1001];

int GetTheMinNumOfRadar(int IslandsCount,DataType Distance);


int main()
{
	int IslandsCount = 0;
	DataType Distance = 0.0;
	int MinNum = 0,icase = 1;
	int i = 0,j = 0;

	while(true)
	{
		cin>>IslandsCount;
		cin>>Distance;
		if (0 == IslandsCount && 0 == Distance)
		{
			break;
		}
		for(i=0;i<IslandsCount;i++)
		{
			cin>>Islands[i].x;
			cin>>Islands[i].y;
		}
		getchar();

		MinNum = GetTheMinNumOfRadar(IslandsCount,Distance);
		cout<<"Case "<<icase<<": "<<MinNum<<endl;
		icase++;
	}


	return 0;
}

int GetTheMinNumOfRadar(int IslandsCount,DataType Distance)
{
	if (0 == IslandsCount)
	{
		return 0;
	}
	int RadarCount = 1;
	DataType tempValue = 0.0;
	Radar_x* pRadar_x = new Radar_x[IslandsCount];
	int i=0,j=0,iIndex = 0;
	//计算小岛与X轴交点
	for (i=0;i<IslandsCount;i++)
	{
		//if ((Distance < Islands[i].y) || (0 > Islands[i].y) )
		if (Distance <abs(Islands[i].y))
		{
			return -1;
		}
		tempValue = sqrtf((Distance*Distance) - (Islands[i].y*Islands[i].y));
		
		pRadar_x[i].x1 = Islands[i].x - tempValue;
		pRadar_x[i].x2 = Islands[i].x + tempValue;		
	}
	Radar_x xTemp;//将小岛与x轴相交的左坐标排序
	for (i=0;i<IslandsCount;i++)
	{
		for (j=i+1;j<IslandsCount;j++)
		{
			if (pRadar_x[i].x1>pRadar_x[j].x1)
			{
				xTemp.x1 = pRadar_x[i].x1;
				xTemp.x2 = pRadar_x[i].x2;

				pRadar_x[i].x1 = pRadar_x[j].x1;
				pRadar_x[i].x2 = pRadar_x[j].x2;

				pRadar_x[j].x1 = xTemp.x1;
				pRadar_x[j].x2 = xTemp.x2;
				
			}
		}
	}
	//计算雷达最小个数
	for (iIndex=0,i=1;i<IslandsCount;i++)
	{	
		for (j=iIndex;j<i;j++)
		{
			if (pRadar_x[j].x2 < pRadar_x[i].x1)
			{
				RadarCount++;
				iIndex = i;
			}
		}

	}

	delete[] pRadar_x;
	
	return RadarCount;
}


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