题目传送门

题意:给一些传感器,范围在r内,再给一些询问点,问这些点能有几个传感器收到,当有墙隔绝时信号减弱,范围变小

分析:set存储传感器,用set的find来查找是否是传感器。因为询问点少,可以枚举询问点的r的范围的所有整数点,+线段相交新模板:)

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
struct Point {
int x, y;
Point() {}
Point(int x, int y) : x (x), y (y) {}
Point operator - (const Point &r) const {
return Point (x - r.x, y - r.y);
}
bool operator < (const Point &r) const {
return x < r.x || (x == r.x && y < r.y);
}
int operator ^ (const Point &r) const { //叉积
return x * r.y - y * r.x;
}
bool operator == (const Point &r) const {
return (x == r.x && y == r.y);
}
};
typedef Point Vector;
Point read_point(void) {
int x, y; scanf ("%d%d", &x, &y);
return Point (x, y);
}
int dot(Vector A, Vector B) {
return A.x * B.x + A.y * B.y;
}
int cross(Vector A, Vector B) {
return A.x * B.y - A.y * B.x;
}
bool on_seg(Point p, Point a, Point b) {
return (cross (a - p, b - p) == 0 && dot (a - p, b - p) < 0);
}
//2 规范相交 1 非规范相交 0 不相交 //有误
int can_seg_seg_inter(Point a1, Point a2, Point b1, Point b2) {
int c1 = cross (a2 - a1, b1 - a1), c2 = cross (a2 - a1, b2 - a1),
c3 = cross (b2 - b1, a1 - b1), c4 = cross (b2 - b1, a2 - b1);
if ((c1 ^ c2) == -2 && (c3 ^ c4) == -2) return 2;
return (on_seg (a1, b1, b2) || on_seg (a2, b1, b2)
|| on_seg (b1, a1, a2) || on_seg (b2, a1, a2));
}
bool check(Point a1, Point a2, Point b1, Point b2) {
if (min (a1.x, a2.x) > max (b1.x, b2.x) ||
min (a1.y, a2.y) > max (b1.y, b2.y) ||
min (b1.x, b2.x) > max (a1.x, a2.x) ||
min (b1.y, b2.y) > max (a1.y, a2.y)) return false;
int c1 = (a1 - a2) ^ (a1 - b1);
int c2 = (a1 - a2) ^ (a1 - b2);
int c3 = (b1 - b2) ^ (b1 - a1);
int c4 = (b1 - b2) ^ (b1 - a2);
return 1ll * c1 * c2 <= 0 && 1ll * c3 * c4 <= 0;
}
int s, r, w, p;
Point p1[15], p2[15];
set<Point> S; int squ(int x) {
return x * x;
} int get_dis2(Point a, Point b) {
return squ (a.x - b.x) + squ (a.y - b.y);
} bool find_senor(Point a, Point b) {
if (S.find (b) != S.end ()) {
int d2 = get_dis2 (a, b);
if (d2 > squ (r)) return false;
int cnt = 0;
for (int i=1; i<=w; ++i) {
//if (can_seg_seg_inter (a, b, p1[i], p2[i])) cnt++;
if (check (a, b, p1[i], p2[i])) cnt++;
}
if (cnt > r) return false;
return d2 <= squ (r - cnt);
}
else return false;
} void run(Point a, vector<Point> &vec) {
for (int i=-r; i<=r; ++i) {
int d = sqrt (squ (r) - squ (i));
for (int j=-r; j<=r; ++j) {
Point b = Point (a.x + i, a.y + j);
if (find_senor (a, b)) vec.push_back (b);
}
}
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
scanf ("%d%d%d%d", &s, &r, &w, &p);
S.clear ();
for (int i=1; i<=s; ++i) {
S.insert (read_point ());
}
for (int i=1; i<=w; ++i) {
p1[i] = read_point ();
p2[i] = read_point ();
}
vector<Point> vec;
for (int i=1; i<=p; ++i) {
Point a = read_point ();
vec.clear ();
run (a, vec);
sort (vec.begin (), vec.end ());
printf ("%d", vec.size ());
for (int i=0; i<vec.size (); ++i) {
printf (" (%d,%d)", vec[i].x, vec[i].y);
}
puts ("");
}
} return 0;
}

  

set+几何 LA 5908 Tracking RFIDs的更多相关文章

  1. STL之map、set灵活使用

    1.LA 5908/UVA1517 Tracking RFIDs 题意:给出s个传感器的位置,以及其感应范围.如果某个方向上有墙,则该方向上感应距离减1.现在有w个墙,给出p个物品的位置,问其能被几个 ...

  2. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  3. 简单几何(求划分区域) LA 3263 That Nice Euler Circuit

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2.那么找出新增的点和边就可以了.用到了判断线段相 ...

  4. LA 4127 - The Sky is the Limit (离散化 扫描线 几何模板)

    题目链接 非原创 原创地址:http://blog.csdn.net/jingqi814/article/details/26117241 题意:输入n座山的信息(山的横坐标,高度,山底宽度),计算他 ...

  5. LA 3263 好看的一笔画 欧拉几何+计算几何模板

    题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...

  6. LA 4676 Geometry Problem (几何)

    ACM-ICPC Live Archive 又是搞了一个晚上啊!!! 总算是得到一个教训,误差总是会有的,不过需要用方法排除误差.想这题才几分钟,敲这题才半个钟,debug就用了一个晚上了!TAT 有 ...

  7. 《 iPhone X ARKit Face Tracking 》

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 本文来自于腾讯Bugly公众号(weixinBugly), 作者:jennysluo,未经作者同意,请勿转载,原文地址:http://mp.w ...

  8. 多目标跟踪(MOT)论文随笔-SIMPLE ONLINE AND REALTIME TRACKING WITH A DEEP ASSOCIATION METRIC (Deep SORT)

    网上已有很多关于MOT的文章,此系列仅为个人阅读随笔,便于初学者的共同成长.若希望详细了解,建议阅读原文. 本文是tracking by detection 方法进行多目标跟踪的文章,在SORT的基础 ...

  9. 多目标跟踪(MOT)论文随笔-SIMPLE ONLINE AND REALTIME TRACKING (SORT)

    网上已有很多关于MOT的文章,此系列仅为个人阅读随笔,便于初学者的共同成长.若希望详细了解,建议阅读原文. 本文是使用 tracking by detection 方法进行多目标跟踪的文章,是后续de ...

随机推荐

  1. 由浅入深剖析.htaccess

    转自:http://blog.csdn.net/21aspnet/article/details/6908025 [-] htaccess文件使用前提 htaccess基本语法介绍 现学现用学习正则表 ...

  2. C/C++不同文件夹下包含头文件的方法及#include的使用

    转自:http://blog.sina.com.cn/s/blog_6e0693f70100so42.html 本文主要介绍了如何不同文件夹下使用预处理器指示符#include. 假设我们有如下一个工 ...

  3. 有关Java的优秀博客集锦

    1. 在java编程中,多线程并发总有些疑惑:如为什么会产生并发?并发会有什么影响?java中提供了哪些处理并发的技术(机制) 关于并发产生的原因,我查了一些资料目前发现有两种原因:一,存在共享的资源 ...

  4. Http返回码

    HTTP协议状态码表示的意思主要分为五类 ,大体是 :   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~   1×× 保留    2×× 表示请求成功地接收    3×× 为完成请求客户需 ...

  5. ps -C nginx --no-header |wc -l

    [root@ok ok]# ps --help|grep C -A all processes -C by command name -V,V show version L list format c ...

  6. PortSentry是入侵检测工具中配置最简单、效果最直接的工具之一

    https://sourceforge.net/projects/sentrytools/ [root@localhost ~]# tar -xzvf portsentry-1.2.tar.gz [r ...

  7. JustSniffer

    http://blog.csdn.net/cnbird2008/article/details/5875781

  8. 与你相遇好幸运,Sails.js自定义responses

    在 /api/responses/ 新建文件 >serviceDBError.js 自定义的数据库错误 >serviceError.js  自定义的数据错误 >serviceSucc ...

  9. Java内存泄露的理解与解决

    依赖于引用判断的内存管理机制 Java中对内存对象的访问,使用的是引用的方式.在Java代码中我们维护一个内存对象的引用变量,通过这个引用变量的值,我们可以访问到对应的内存地址中的内存对象空间.在Ja ...

  10. 设计模式学习之适配器模式(Adapter,结构型模式)(14)

    参考链接:http://www.cnblogs.com/zhili/p/AdapterPattern.html一.定义:将一个类的接口转换成客户希望的另一个接口.Adapter模式使得原本由于接口不兼 ...