http://poj.org/problem?id=1328

思路:

1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解

2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆心允许范围,问题转化为在许多圆心允许范围内取尽可能少的点,也即在许多线段上取尽可能少的点,使得所有线段上都有点被取到

3.从左往右考虑,完全在左边的线段肯定要取点,如果这个点在当前线段上已经取了,明显就可以忽略当前线段,明显在线段上的最优点是右端点

 #include <iostream>
#include <cmath>
using namespace std; typedef pair<double,double> p;
p pos[];
p temp[];
int n,d; int MERGE(int s,int e){
int mid=(e+s)/;
int i=s,j=mid,k=s;
while(i<mid&&j<e){
if(pos[i].first>pos[j].first||(pos[i].first==pos[j].first&&pos[i].second>pos[j].second)){
temp[k].first=pos[j].first;
temp[k].second=pos[j].second;
k++;
j++;
}
else {
temp[k].first=pos[i].first;
temp[k].second=pos[i].second;
k++;
i++;
}
}
int kk=k;
for(;i<mid;i++){
pos[kk].first=pos[i].first;
pos[kk].second=pos[i].second;
kk++;
}
for(int ii=s;ii<k;ii++){
pos[ii].first=temp[ii].first;
pos[ii].second=temp[ii].second;
}
return ;
}
int MERGE_SORT1(int s,int e){
if(e-s<){
return ;
}
int mid=(s+e)/;
MERGE_SORT1(s,mid);
MERGE_SORT1(mid,e);
MERGE(s,e);
return ;
} int solve(){
double x,y;
double sq;
bool flag=false;
for(int i=;i<n;i++){
cin>>x>>y;
if(y>d){
flag=true;
continue;
}
if(y<){
i--;
n--;
continue;
}
sq=sqrt((double)(d*d-y*y));
pos[i].first=x-sq;
pos[i].second=x+sq;
}
if(flag)return ;
MERGE_SORT1(,n);
int ans=;
double mx;
mx=pos[].second;
for(int i=;i<n;i++){
if(mx<pos[i].first){
ans++;
mx=pos[i].second;
}
else if(mx>pos[i].second){
mx=pos[i].second;
}
}
return ans;
} int main(){
int ci=;
while(ci++){
cin>>n>>d;
if(n<=)break;
int ans=solve();
if(ans){
cout<<"Case "<<ci-<<":"<<" "<<ans<<endl;
}
else{
cout<<"Case "<<ci-<<":"<<" "<<-<<endl;
}
}
return ;
}

POJ 1328 Radar Installation 贪心 难度:1的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  3. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  4. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  6. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  7. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  8. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  9. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. Linux数字权限解释

    linux系统文件夹644.755.777权限设置详解 ,左至右,第一位数字代表文件所有者的权限,第二位数字代表同组用户的权限,第三位数字代表其他用户的权限. 而具体的权限是由数字来表示的,读取的权限 ...

  2. [html] HTML结构的语义化

    原文链接:http://www.cnblogs.com/freeyiyi1993/p/3615179.html 1.什么是html语义化 选择合适的html标签,便于开发者阅读和写出更优雅的代码的同时 ...

  3. Spring3 表达式语言(SpEL)介绍

    转载自:http://iyiguo.net/blog/2011/06/19/spring-expression-language/ 下一版本 项目需要使用到SpEL ,做一个保存.

  4. 数据库索引B+树

    面试时无意间被问到了这个问题:数据库索引的存储结构一般是B+树,为什么不适用红黑树等普通的二叉树? 经过和同学的讨论,得到如下几个情况: 1. 数据库文件是放在硬盘上,每次读取数据库都需要在磁盘上搜索 ...

  5. 【ros】Create a ROS package:package dependencies报错

    $rospack depends1 beginner_tutorials 报错:Erros:could notn call python function 'rosdep2.rospack.init_ ...

  6. 解析excel表格为DataSet

    using System;using System.Collections.Generic;using System.Data;using System.Data.OleDb;using System ...

  7. 百度编辑器ueditor获取不到内容?请把form放在table等其他元素最外面

    百度编辑器ueditor获取不到内容?请把form放在table等其他元素最外面. <form name="form" method="post" act ...

  8. 制作Aspose CHM文档的过程记录

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  9. this 指向

    this-->当前行为发生的主体就是this,但是this是谁和这个方法在哪执行的或者在哪定义的都没有半毛钱的关系 如何的区分JS中的this? 1)函数执行,看函数名前面是否有".& ...

  10. input上传图片 显示预览信息

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...