POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation
https://vjudge.net/problem/POJ-1328
题目:
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.
We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.
Figure A Sample Input of Radar Installations
Input
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.
The input is terminated by a line containing pair of zeros
Output
Examples
Input
3 2
1 2
-3 1
2 1 1 2
0 2 0 0
Output
Case 1: 2
Case 2: 1
分析:
写完AB之后发现真的不知道该怎么写C了。。。。几乎没什么坑现在还能踩了,于是又加一个A
题意很好理解,理解完之后直接干,用的二维贪心,,,
然后

mle。。。。Wawawa
从网上找的题解,都和我不同的思路????
wtf????
我的思路没毛病啊??
然后自己又仔细用数学证明了一遍,发现如果两个同样很远的点就会出现问题,我的贪心策略会使得灯塔++
emmmmmmmmm那就只能重打一遍了
错误代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
struct A {
double x,y;
} a[];
int num = ;
int n;
double d;
int count0 = ;
bool cmp(A a, A b) {
if(a.x < b.x)
return true;
if(fabs(a.x - b.x) <= eps && a.y > b.y)
return true;
return false;
}
int f(int x) {
int xx = a[x].x + sqrt(d*d-a[x].y*a[x].y);
num ++;
for(int i = x+; i < n; i ++) { //p(i)
if(sqrt( a[i].y*a[i].y + (a[i].x-xx)*(a[i].x-xx) ) > d) {
f(i);
return ;
}
}
return ;
}
int main() {
while(~scanf("%d%lf",&n,&d) && (n != || d != 0.0)) {
num = ;
count0 ++;
int sta = ;
for(int i = ; i < n; i ++) {
slf(a[i].x) slf(a[i].y);
if(a[i].y > d) {
sta = ;
}
}
ps("Case ") p(count0) ps(": ");
if(sta == ) {
p(-) pn continue;
}
sort(a,a+n,cmp);
f();
p(num) pn
}
return ;
}
AC代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
struct A {
double l,r;
int sta ;
} a[];
int n;
double d;
int count0 = ;
int num = ;
int count1 = ;
bool cmp(A a, A b) {
if(a.r!=b.r)
return a.r<b.r;
return a.l>b.l;
return false;
} int f(int x) {
count1 ++;
for(int i = x+; i < n; i++) {
if(a[i].l > a[x].r) {
f(i);
return ;
}
}
return ;
} int main() {
while(~scanf("%d%lf",&n,&d) && (n != || d != 0.0)) {
num = ;
count0 ++;
count1 = ;
int sta = ;
double x,y;
for(int i = ; i < n; i ++) {
slf(x) slf(y);
if(y > d) {
sta = ;
}
a[i].l = x-sqrt(d*d-y*y);
a[i].r = x+ sqrt(d*d-y*y);
}
ps("Case ")
p(count0)
ps(": ");
if(sta == ) {
p(-) pn
continue;
}
sort(a,a+n,cmp);
//f(0);
double end=-0x3f3f3f3f;//横坐标要很小....因为..你懂的
for(int i=; i<n; i++) {
if(end<a[i].l) {
end=a[i].r;
count1++;
}
} p(count1) pn
} return ;
}
POJ 1328 Radar Installation 贪心 A的更多相关文章
- 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 ...
- 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 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- Java中运行时异常和非运行时异常什么鬼?
Java中的异常分类 RuntimeException(也称unchecked exceptions,运行时异常) 就是我们在开发中测试功能时程序终止,控制台出现的异常.(一般来说,出现运行时异常基本 ...
- μC/Probe尝鲜
μC/Probe 1.添加文件 2.配置probe_com_cfg.h 2.1.选择接口 #define PROBE_COM_CFG_RS232_EN DEF_ENABLED /* Configure ...
- toString 和new String()区别
public class NewStringTestDemo { public static void main(String[] args) { String s = "你好"; ...
- 基于windows平台搭建elasticsearch
部署准备 elasticsearch-6.0.1.zip--https://www.elastic.co/downloads/elasticsearch elasticsearch-head-mast ...
- 让openvpn自启动的命令笔记(windows)
"C:\Program Files\OpenVPN\bin\openvpn.exe" --client-config-dir "C:\Program Files\Open ...
- MFC---关于string.h相关函数
1.在VS2005中使用strcpy.strcat.sprintf出现如:mfc中'strcpy' was declared deprecated警告 这是因为VS2005中认为CRT中的一组函数如果 ...
- Linux 进程通信方式
转载文章 进程通信的方式 管道( pipe ): 管道包括三种: 普通管道PIPE: 通常有两种限制,一是单工,只能单向传输;二是只能在父子或者兄弟进程间使用. 流管道s_pipe: 去除了第一种限制 ...
- Nginx – access_log格式及配置
日志格式 日志内容 192.168.199.164 – jeson [14/Apr/2018:07:17:09 +0800] “GET /?feed=rss2 HTTP/1.1” 200 13883 ...
- zabbix钉钉报警
我们在钉钉上建立群聊,然后在群聊上添加钉钉机器人: 编写,脚本需要放在zabbix 的alertscripts目录下(如果不知道该目录的位置,可以使用find命令查找) find / -iname a ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...