【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][ ...
随机推荐
- 梦想MxWeb3D协同设计平台 2019.02.28更新
梦想MxWeb3D协同设计平台 2019.02.28更新 SDK开发包下载地址: http://www.mxdraw.com/ndetail_10130.html 在线演示网址: http://www ...
- 当ECharts碰到TWaver
百度公司的ECharts发展迅速,已经成为HTML5 Chart的佼佼者,这让大家骄傲:中国人终于也有世界级的开源通用UI产品了.正如其网站所说,它是百度的,是中国的,也是世界的.想想那些年,我们追逐 ...
- HDU - 4810 - Wall Painting (位运算 + 数学)
题意: 从给出的颜料中选出天数个,第一天选一个,第二天选二个... 例如:第二天从4个中选出两个,把这两个进行异或运算(xor)计入结果 对于每一天输出所有异或的和 $\sum_{i=1}^nC_{n ...
- UVA-1368 DNA Consensus String(思路)
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m ...
- [Python3网络爬虫开发实战] 1.1-Python3的安装
既然要用Python 3开发爬虫,那么第一步一定是安装Python 3.这里会介绍Windows.Linux和Mac三大平台下的安装过程. 1. 相关链接 官方网站:http://python.org ...
- linux more-显示文件内容,每次显示一屏
博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作.more名单中 ...
- swoft| 源码解读系列二: 启动阶段, swoft 都干了些啥?
date: 2018-8-01 14:22:17title: swoft| 源码解读系列二: 启动阶段, swoft 都干了些啥?description: 阅读 sowft 框架源码, 了解 sowf ...
- LINUX-磁盘空间
df -h 显示已经挂载的分区列表 ls -lSr |more 以尺寸大小排列文件和目录 du -sh dir1 估算目录 'dir1' 已经使用的磁盘空间' du -sk * | sort -rn ...
- vim基础(二)
上一篇提到了插入与删除.定位.复制与粘贴以及退出与保存几项基本操作,这篇继续整理其他常用命令. 撤销与替换 首先是我们在输入过程中不小心打错了,或者误删了,怎么恢复?在word里我们有ctrl+Z,v ...
- python之cookbook-day02
第一章:数据结构和算法 1.2 解压可迭代对象赋值给多个变量 问题: 如果一个可迭代对象的元素个数超过变量个数时,会抛出一个 ValueError .那么 怎样才能从这个可迭代对象中解压出 N 个元素 ...