Radar Installation(利用数据有序化进行贪心选择)
English appre:
an infinite straight line:一条无限长的直线
on the coasting:在海岸线上
Cartesian coordinate system,
题目地址:http://poj.org/problem?id=1328
我的代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct dao
{
double x,y;
}da[10000];
bool cmp(dao a,dao b)
{
return (a.y<b.y)||(a.y==b.y && a.x>b.x);
} int main()
{
int n,d;
double x1,y1;
int k=0;
while(~scanf("%d%d",&n,&d)&&(n||d))
{
int ans=1;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&x1,&y1);
da[i].x=x1-sqrt((double)d*(double)d-(double)y1*y1);
da[i].y=x1+sqrt((double)d*(double)d-(double)y1*y1);
if((d-y1)<0||d<=0) ans=-1;
} if(ans==-1)
{
printf("Case %d: -1\n",++k);
continue;
}
else
{
sort(da,da+n,cmp);
double t1=da[0].y;
for(int i=1;i<n;i++)
if(da[i].x>t1)//要是用=号,有些数据不可通过。
{
ans++;
t1=da[i].y;//更新右范围
}
printf("Case %d: %d\n",++k, ans);
}
}
}
Radar Installation(利用数据有序化进行贪心选择)的更多相关文章
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
/* * URAL_1014.cpp * * Created on: 2013年10月11日 * Author: Administrator */ #include <iostream> ...
- Radar Installation(POJ 1328 区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68578 Accepted: 15 ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
- (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)
/* * UVA_10026.cpp * * Created on: 2013年10月10日 * Author: Administrator */ #include <iostream> ...
- 【贪心】「poj1328」Radar Installation
建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- 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 (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- 一些linux软件国内源
1. ubuntu 版本号 Ubuntu 12.04 (LTS)代号为precise. Ubuntu 14.04 (LTS)代号为trusty. Ubuntu 15.04 代号为vivid. Ubun ...
- The ADB binary found at ... 虚拟机运行错误
虚拟机问题,可以说差点扼杀我开发 APP 的乐趣,哼,最后请教了一下辉哥(学长),终于解决 —— 用真机调试.下面是步骤: 首先,检查一下真机连接需要的 SDK 是否安装,未安装,勾选进行安装 接着用 ...
- npm run build 打包后空白页解决问题两种情况
问题一:assetsPublicPath配置错误 解决办法:打开config/index.js文件 build:{ // assetsPublicPath: '/' ass ...
- 【转】为什么使用length获取Java数组的长度
记得vamcily 曾问我:“为什么获取数组的长度用.length(成员变量的形式),而获取String的长度用.length()(成员方法的形式)?” 我当时一听,觉得问得很有道理.做同样一件事情, ...
- Go 使用小记
1.不能使用在运行时计算的值实例化这样的数组. 而是使用make初始化具有所需长度的切片. db := ConnMysql() rows, err := db.Query("select r ...
- spring boot中通用应用程序属性
可以在application.properties文件内部application.yml,文件内部或命令行开关中指定各种属性.本附录提供了常见的Spring Boot属性列表以及对使用它们的基础类的引 ...
- JMeter-做性能测试从何开始
JMeter-性能测试 参考文档:https://jmeter.apache.org/usermanual/boss.html 一.问题 1.预计的平均用户数是多少(正常负载)? 2.预计的高峰用户数 ...
- centos7安装显示中文
系统通过环境变量LANG设置语言格式编码 查看当前语言环境 echo $LANG 查看是否安装中文语言,Linux中通过locale来设置程序运行的不同语言环境 locale -a | grep 'z ...
- 【33】卷积步长讲解(Strided convolutions)
卷积步长(Strided convolutions) 卷积中的步幅是另一个构建卷积神经网络的基本操作,让我向你展示一个例子. 如果你想用3×3的过滤器卷积这个7×7的图像,和之前不同的是,我们把步幅设 ...
- Wannafly Camp 2020 Day 3F 社团管理 - 决策单调性dp,整体二分
有 \(n\) 个数构成的序列 \({a_i}\),要将它划分为 \(k\) 段,定义每一段的权值为这段中 \((i,j) \ s.t. \ i<j,\ a_i=a_j\) 的个数,求一种划分方 ...