【POJ 1328】 Radar Installation
【题目链接】
http://poj.org/problem?id=1328
【算法】
每个雷达都位于笛卡尔坐标系的x轴上,因此,对于每个岛屿,我们都可以用勾股定理算出它的有效管辖区域
那么,问题就被转化成了 : 给定若干个区间,要求每个区间内都要有一个点,最小化点的个数
我们将这些区间按左端点排序,然后贪心,即可
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 1010 int n,d,i,x,y,ans,TC;
double dis,pos;
bool flag; struct info
{
double l,r;
} a[MAXN]; inline bool cmp(info a,info b)
{
return a.l < b.l;
} int main()
{ while (scanf("%d%d",&n,&d) != EOF && n && d)
{
flag = false;
for (i = ; i <= n; i++)
{
scanf("%d%d",&x,&y);
if (y > d) flag = true;
dis = sqrt(d*d-y*y);
a[i] = (info){x-dis,x+dis};
}
if (flag)
{
printf("Case %d: %d\n",++TC,-);
continue;
}
sort(a+,a+n+,cmp);
ans = ; pos = a[].r;
for (i = ; i <= n; i++)
{
if (a[i].l > pos)
{
ans++;
pos = a[i].r;
} else pos = min(pos,a[i].r);
}
printf("Case %d: %d\n",++TC,ans);
} return ; }
【POJ 1328】 Radar Installation的更多相关文章
- 【OpenJ_Bailian - 1328】Radar Installation (贪心)
Radar Installation 原文是English,直接上中文 Descriptions: 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任 ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- openssl 下的对称加密和非对称加密
对称加密: 在加密和解密过程中使用相同的密钥, 或是两个可以简单地相互推算的密钥的加密算法. 非对称加密: 也称为公开加密, 它需要一个密钥对, 一个是公钥, 一个是私钥, 一个负责加密, 一个负责解 ...
- 模板—AC自动机
#include<iostream> #include<cstdio> #include<cstring> using namespace std; struct ...
- Java基础——异常
一.什么是异常 异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.事实上,异常本质上是程序上的错误,包括程序逻辑错误和系统错误.比如使用空的引用.数组下标越界. ...
- 3D赛瓦号——整装待发!
随着岁末将至,twaver开发团队依旧马不停蹄,3d产品功能持续更新,新特效和功能目不暇接.现在,我们就利用一些新功能,制作一个全新“赛瓦号”飞船,大家看一下仿真程度是否有质的不同? 网页3d技术正在 ...
- Gym - 101670H Dark Ride with Monsters(CTU Open Contest 2017 贪心)
题目: A narrow gauge train drives the visitors through the sequence of chambers in the Dark Ride attra ...
- 洛谷 1182 数列分段Section II
[题解] 最大值最小化,那么一般要联想到二分.二分一个最大值,然后check一下能否分成小于等于m段即可. #include<cstdio> #include<algorithm&g ...
- hadoop 3.0.0新特性
1.Minimum required Java version increased from Java 7 to Java 8 java最低支持版本变成java8 2.Support for eras ...
- 创建Maven版Java工程
步骤: 创建成功后,如图:
- Maven学习总结(30)——Maven项目通用三级版本号说明
项目版本号说明 当前版本号:1.0.0-SNAPSHOT 本项目采用通用的三级版本号,版本号格式是[主版本号].[副版本号].[修复版本号]-[稳定状态],如:1.0.0-SNAPS ...
- 洛谷—— P1657 选书
https://www.luogu.org/problem/show?pid=1657 题目描述 学校放寒假时,信息学奥赛辅导老师有1,2,3……x本书,要分给参加培训的x个人,每人只能选一本书,但是 ...