//
// main.c
// poj1328
//
// Created by 韩雪滢 on 11/16/16.
// Copyright © 2016 韩雪滢. All rights reserved.
/*
*不完全解题报告
*实现了解题思路,单个测试用例输入正确,没有写循环输入
*如发现输入结果错误,请在下面留言,不胜感激
*
*解题思路:
*贪心算法
*在读入每个岛屿的坐标时,同时计算以该岛屿为圆心,雷达范围半径为半径的圆与x轴相交的横坐标范围
*如果范围不重叠,雷达+1
*/
#include <stdio.h>
#include <mm_malloc.h>
#include <math.h>
struct island{
int x;
int y;
int start;
int terminal;
};
struct radar{
int x;
int y;
int radius;
};
struct island *inIslands;
struct radar *setRadars;
int *prior;
int radarNum(int n){
int k,i,j,m;
int result=1;
for(k=0;k<n;k++)
prior[k]=k;
for(i=0;i<n;i++){
for(j=i-1;(j>=0) && (inIslands[i].start < inIslands[prior[j]].start);j--)
{
prior[j+1]=prior[j];
}
prior[j+1]=i;
}
for(m=0;m<n-1;m++){
if(inIslands[m].terminal<inIslands[m+1].start)
result++;
}
return result;
}
int main(int argc, const char * argv[]) {
int n,d;
scanf("%d%d",&n,&d);
inIslands = (struct island*)malloc(sizeof(struct island)*n);
prior = (int*)malloc(sizeof(int)*n);
int i;
for(i=0;i<n;i++){
scanf("%d%d",&inIslands[i].x,&inIslands[i].y);
int temp = sqrt(d*d-inIslands[i].y*inIslands[i].y);
inIslands[i].start = inIslands[i].x-temp;
inIslands[i].terminal = inIslands[i].x+temp;
}
int result = radarNum(n);
printf("结果:%d
",result);
int j;
for(j=0;j<n;j++){
printf("岛屿%d:[%d,%d]
",prior[j],inIslands[prior[j]].start,inIslands[prior[j]].terminal);
}
return 0;
}