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. AFNetworking请求中含有中文时程序崩溃

    出现error: Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error ...

  2. [转载] 一篇文章带你了解Paxos算法

    原文: http://dockone.io/article/640 [编者的话]本文是Quora上关于Paxos算法的回答,两位答者分别从不同的角度描述Paxos算法.Vineet Gupta的回答细 ...

  3. HashMap遍历

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  4. 最大堆的插入/删除/调整/排序操作(图解+程序)(JAVA)

    堆有最大堆和最小堆之分,最大堆就是每个节点的值都>=其左右孩子(如果有的话)值的完全二叉树.最小堆便是每个节点的值都<=其左右孩子值的完全二叉树. 设有n个元素的序列{k1,k2,..., ...

  5. quatz2d使用注意点

    1使用图层设置圆角,cornerRadiu一般设置为10的参数,若设置圆形,cornerRadiu设为宽度的一半

  6. hiho_1055_刷油漆

    题目大意 一棵树,每个节点都有相应的value值.从根开始选择M个节点相互连通,使得这些节点的value值之和最大. 题目链接:[刷油漆][1] 题目分析 典型的树形dp,dp[i][j] 表示以节点 ...

  7. libsvm-3.21使用文档

    Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. (可用于分 ...

  8. VB6.0调用DLL

    目录 第1章 VB6.0调用DLL    1 1 VC++编写DLL    1 1.1 使用__stdcall    1 1.2 使用 .DEF 文件    1 2 简单数据类型    2 2.1 传 ...

  9. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 增、查、改、删操作

    Create, Read, Update, and Delete operations¶ 5 of 5 people found this helpful By Tom Dykstra The Con ...

  10. Technical notes fornight

    1.8.2016 Royal trumpeters heralded the beginning of the annual ceremony, as Norway's royal family an ...