【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][ ...
随机推荐
- jenkins自动部署测试环境
构建脚本如下: echo "当前目录":$(pwd)echo "当前时间":$(date +%Y-%m-%d_%H:%M)find ./ -type f -na ...
- eBPF监控工具bcc系列五工具funccount
eBPF监控工具bcc系列五工具funccount funccount函数可以通过匹配来跟踪函数,tracepoints 或USDT探针.例如所有以vfs_ 开头的内核函数. ./funccount ...
- BeanFactory和ApplicationContext
BeanFactory是一个类的通用工厂,可以创建并管理各种类的对象 Bean工厂是Spring框架最核心的接口,它提供了高级Ioc的配置机制.BeanFeactory使管理不同类的Java对象成为可 ...
- js实现汉字中文排序的方法 例如:省市列表的排序
localeCompare() 1.数组内的元素是中文字符串的简单排序 var arr = ['南京', '北京', '上海', '杭州', '深圳']; function sortChinese ( ...
- scrapy 按顺序抓取text内容
需求:获得如下li.clearfix 下的所有text,并且按顺序输出 1. x.css('div.reply-doc h4 a::text').extract(); 2. x.css('div.r ...
- MSSQL获取指定日期的SQL语句
--1.一个月第一天的 SELECT DATEADD(mm,DATEDIFF(mm,0,getdate()),0) --2.本周的星期一 SELECT DATEADD(wk,DATEDIFF(wk,0 ...
- ACM数论常用知识完全解读
此版本纯属扯淡....... 一个一个来起.
- 转载 - C++ - placement new
出处:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 有关placement new ...
- 兼容IE8 addEventListener、removeEventListener 函数
//兼容bind函数 if(!Function.prototype.bind){ Function.prototype.bind = function(){ if(typeof this !== 'f ...
- codevs1018 单词接龙
题目描述 Description 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次), ...