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. js图片跑马灯效果

    <style. type="text/css">body{margin:0px auto; padding:0px;}ul,li{margin:0px; padding ...

  2. Javascript中typeof instanceof constructor的区别

    typeof typeof,是一个运算符,运算中需要一个操作数,运算的结果就是这个操作数的类型,运算的结果是一个字符串.他有一定的局限性,对于对象类型的值,只能得到一个object结果,却不能精确得到 ...

  3. Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别总结

    Mysql中utf8_general_ci与utf8_unicode_ci有什么区别呢?在编程语言中,通常用unicode对中文字符做处理,防止出现乱码,那么在MySQL里,为什么大家都使用utf8_ ...

  4. 使用ar命令删除iOS静态库重复编译的.o文件

    关于 xcode引入第三方静态类库 duplicate symbol _OBJC_XXX 重复编译错误 看这里 http://www.cnblogs.com/cocoajin/p/3917709.ht ...

  5. navigator.userAgent.indexOf来判断浏览器类型

    navigator.userAgent.indexOf来判断浏览器类型 (2011-03-03 11:30:40) 转载▼ 标签: 杂谈   来源:http://xtaai5233.blog.163. ...

  6. selenium+python笔记4

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...

  7. [mondrian] 分析一个简单的schema文件

    <?xml version="1.0" encoding="UTF-8"?> <Schema name="Mondrian" ...

  8. python知识总结

    LIST:Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素,用[]包裹.例如 classmates = ['Michael', 'Bob', 'T ...

  9. hdu 4033Regular Polygon(二分+余弦定理)

    Regular Polygon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)T ...

  10. 百度地图API:利用瓦片生成工具,自定义背景图片

    参考酸奶小妹的博文<[百度地图API]如何制作一张魔兽地图!!——CS地图也可以,哈哈哈> (http://www.cnblogs.com/milkmap/archive/2011/05/ ...