POJ 1328 Radar Installation 贪心 难度:1
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的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- Web浏览器的缓存机制
Web缓存的工作原理 所有的缓存都是基于一套规则来帮助他们决定什么时候使用缓存中的副本提供服务(假设有副本可用的情况下,未被销毁回收或者未被删除修改).这些规则有的在协议中有定义(如HTTP协议1.0 ...
- 转:C/C++中,空数组、空类、类中空数组的解析及其作用
转自:http://blog.sina.com.cn/s/blog_93b45b0f01015s95.html 我们经常会遇到这些问题: (1)C++中定义一个空类,他们它的大小(sizeof) 为多 ...
- C#_List转换成DataTable
/// <summary> /// 讲list集合转换成datatable /// </summary> /// <param name="list" ...
- phalcon: 表单
以实例为说明: controller <?php use \Phalcon\Forms\Form; use \Phalcon\Forms\Element\Text; use \Phalcon\F ...
- refreshLayout 和 滑动控件的冲突解决
listView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollSt ...
- program testy data
做项目得用数据吧,拿去.... 1.Data.gov搜索 美国政府去年承诺使所有政府数据都能在网上免费获得.这个网站是第一阶段,作为一个门户网站,囊括了从气候到犯罪的一切惊人的信息. 2. 美 ...
- as(C# 参考)
原文地址:https://msdn.microsoft.com/zh-cn/library/cscsdfbt(v=vs.110).aspx 可以使用 as 运算符执行转换的某些类型在兼容之间的引用类型 ...
- robotframework笔记19
后处理输出 使用时自动测试 在测试执行报告和日志生成,并使用它 分别允许创建自定义报告和日志以及结合 和合并的结果. 使用Rebot 简介 rebot [options] robot_outputs ...
- q和blockquote标签的区别
q用来分离文本中的引语,定义一个短的引用.该标签会对引用的文本加双引号,一般情况很少用,博客论坛系统会用得多一些: blockquote用于对长文本的引用,用来定义一段引语,标签内的内容会自动有缩进: ...
- MyBatis执行过程显示SQL语句的log4j配置
log4j.properties文件 log4j.rootLogger=debug,stdout,logfile log4j.appender.stdout=org.apache.log4j.Co ...