POJ1328 Radar Installation

Description

Assume thecoasting is an infinite straight line. Land is in one side of coasting, sea inthe other. Each small island is a point locating in the sea side. And any radarinstallation, locating on the coasting, can only cover d distance, so an islandin the sea can be covered by a radius installation, if the distance betweenthem is at most d. We use Cartesian coordinate system, defining the coasting is the x-axis. Thesea side is above x-axis, and the land side below. Given the position of eachisland in the sea, and given the distance of the coverage of the radarinstallation, your task is to write a program to find the minimal number ofradar installations to cover all the islands. Note that the position of anisland is represented by its x-y coordinates. 

POJ1328 Radar Installation_第1张图片

Input

The input consistsof several test cases. The first line of each case contains two integers n(1<=n<=1000) and d, where n is the number of islands in the sea and d isthe distance of coverage of the radar installation. This is followed by n lineseach containing two integers representing the coordinate of the position ofeach island. Then a blank line follows to separate the cases. The input is terminated by a line containing pair of zeros 

Output

For each test caseoutput one line consisting of the test case number followed by the minimalnumber of radar installations needed. "-1" installation means nosolution for that case.

Sample Input

3 2

1 2

-3 1

2 1

 

1 2

0 2

 

0 0

Sample Output

Case 1: 2

Case 2: 1

 

题目大意:海岸为x轴,海岸的一边有若干个小岛,问在x轴上至少建立多少个雷达站,可以把小岛都覆盖。

输入第一行为n和d,n是小岛的数量,d是雷达的辐射半径。接下来n行是n个小岛的坐标,输入为0 0是终止。

#include
#include
#include
using namespace std;
struct land
{
	double x,y;
	double l_range,r_range;
}s[1001];
int cmp(const void *a,const void *b);

int main()
{
	int n,d,i,cas=0,cnt;
	double temp;
	while(cin>>n>>d&&(n+d!=0))
	{
		bool istrue=true;
		cnt=1;
		for(i=0;i>s[i].x>>s[i].y;
			if(s[i].y>d)
				istrue=false;
		}
		if(!istrue)
			cout<<"Case "<<++cas<<": -1"<temp)//如果右边岛屿左限大于左边岛屿右限,那么必须增加一个雷达站
			{
				cnt++;
				temp=s[i].r_range;
			}
			else if(s[i].r_range(*(land*)b).x?1:-1;
}

总结:这道题花了3个多小时。但是有收获。

           1.结构体排序,选修课上刚刚讲过。

           2.sqrt(double)传int提交的话会出错

           3.贪心思想,不断比较,赋值,比较。。。

你可能感兴趣的:(c/c++)