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

Re:我的思路和别人的不太一样,大牛帮忙看看对不对

Posted by buaahanjunwei at 2010-12-15 20:51:14 on Problem 1328
In Reply To:我的思路和别人的不太一样,大牛帮忙看看对不对 Posted by:cigaring at 2010-10-26 13:25:24
这个思路不对的
首先看这组数据
4 5
-5 3
-3 5
2 3
3 3
排序后还是这个顺序
如果按你的方法,应该得出来的是3,因为放置了第一个雷达(假设在A点)后,检测发现第二个点(-3,5)不再覆盖范围内,因此又开始以(-3,5)为点找新雷达的位置。
但是如果此时第二个点的横坐标小于A的横坐标,那么第二个点应该可以被覆盖,需要做的就是将A点向左调整。
因此你的方法,还应该加一个检测过程。这里你可以参考下我的程序。

#include <stdio.h>
#include <math.h>

typedef struct Point {
	int x;
	int y;
} Point;

#define LINE 1000

int group[LINE][2] = {0};
int result[LINE] = {0};
Point ilands[LINE];

int cmp(const Point * , const Point *);

int main()
{
	int i , j , k;
	int x , y;
	int n , d;
	double radar;

	scanf("%d%d" , &n , &d);

	k = 0;
	while(n!=0)
	{
		for(i=0 ; i<n ; i++)
		{
			scanf("%d%d" , &x , &y);
			if(y > d)
				result[k] = -1;
			ilands[i].x = x;
			ilands[i].y = y;
		}
		if(result[k] != -1)
		{
			qsort(ilands , n , sizeof(Point) , cmp);
			//Greedy algorithm
			//for(i=0 ; i<n ; i++)
			//	printf("(%d , %d)\n" , ilands[i].x , ilands[i].y);

			for(i=0 ; i<n ; )
			{
				radar = sqrt(d*d - ilands[i].y*ilands[i].y) + ilands[i].x;
				result[k]++;
				for(j=i+1 ; j<n ; j++)
				{
					if( pow(ilands[j].x-radar , 2) + pow(ilands[j].y , 2) > d*d )
					{
						//readjust radar in order to check whether point j can be surrounded
						if((double)ilands[j].x > radar)
							break;
						
						radar = sqrt(d*d - ilands[j].y*ilands[j].y) + ilands[j].x;
					}
				}
				i = j;
			}
		}
		k++;
		scanf("%d%d" , &n , &d);
	}
	
	for(i=0 ; i<k ; i++)
		printf("Case %d: %d\n" , i+1 , result[i]);
	return 0;
}

int cmp(const Point * a , const Point * b)
{
	return (a->x - b->x);
}


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