fzuoj1111Radar Installation (贪心)
题目大意是在海岸线布置n个雷达,要求雷达的范围要包含所有的小岛;
思路:逆向思维把小岛看成一个个范围,与海岸线的交集,从最左端的开始找 (贪心最左端的点),接着不用一个一个去遍历,直接用前一个的右端点去替换下一个的左端点。。。。直至最后一个点。大致思想就是贪心,还是比较正常的题,适合刚学c语言的新生做(小白我就是一枚)。
下面是代码:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{
double left,right;
}island[];
bool cmp(node a,node b)
{
return a.left < b.left;
}
int main()
{
double x,y,d,temp;
int i,cnt,n,k=;
bool flag;
while(scanf("%d%lf",&n,&d)&&!(n==&&d==))
{
k++;
flag=false;
for(i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
if(y > d||d<)
{
flag = true;
}
island[i].right = x+sqrt(d*d-y*y);///岛屿右端点初始化
island[i].left = x-sqrt(d*d-y*y);///岛屿左端点初始化
}
if(flag)
{
printf("Case %d: -1\n",k);
continue;
}
sort(island,island+n,cmp);
temp=island[].right;
cnt=;
for(i=; i<n; i++)
{
if(island[i].right <= temp)
{
temp = island[i].right;///岛屿右端点的替换
}
else if(island[i].left > temp)
{
cnt++;
temp = island[i].right;
}
}
printf("Case %d: %d\n",k,cnt);
}
return ;
}
fzuoj1111Radar Installation (贪心)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj1328Radar Installation 贪心
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64472 Accepted: 14 ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- Radar Installation 贪心
Language: Default Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42 ...
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- Radar Installation(贪心,可以转化为今年暑假不ac类型)
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- 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 ...
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
随机推荐
- iOS,手势识别简单使用
1.iOS目前支持的手势识别(6种) 2.点按手势和慢速拖动手势简单使用 iOS目前支持的手势识别(6种) UITapGestureRecognizer(点按) UIPinchGestureRecog ...
- js数组方法扩展
/** * Created by Administrator on 2016/9/1. */ //数组去重 Array.prototype.unique = function(){ this.sort ...
- 360浏览器下载excel问题解决方式
亲们有没有碰到过今天我遇到的这件事. 如果使用简单的链接.或者get方式提交的表单,去下载excel,那么360浏览器就会有问题. 问题是:它没把我用java生成的excel表格下载,而是去把我的列表 ...
- kali driftnet
语法 : driftnet [options] [filter code] 主要参数: -b 捕获到新的图片时发出嘟嘟声 -i interface 选择监 ...
- 【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。
There are many kinds of testing which really made me confused. To be honest, I've never heard of som ...
- 使用Vue构建中(大)型应用
init 首先要起一个项目,推荐用vue-cli安装 $ npm install -g vue-cli $ vue init webpack demo $ cd demo $ npm install ...
- Overview of the Oppia codebase(Oppia代码库总览)
Oppia is built with Google App Engine. Its backend is written in Python, and its frontend is written ...
- 数据库中老师学生家长表添加自动同意好友自动(AgreeAddingFriend ),默认为True
数据库中老师学生家长表添加自动同意好友自动(AgreeAddingFriend ),默认为True alter table Sys_User add AgreeAddingFriend bit alt ...
- 夺命雷公狗----Git---7---GitHub当仓库本地使用(完)
首先我们将github上的东西克隆到本地: 然后在本地创建一个文件夹,然后进入git命令行: 成功后如下所示: 将仓库里面的内容给克隆到本地了... 然后创建一个index.html然后添加进去: 在 ...
- HDU 4289:Control(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...