set+几何 LA 5908 Tracking RFIDs
题意:给一些传感器,范围在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的更多相关文章
- STL之map、set灵活使用
1.LA 5908/UVA1517 Tracking RFIDs 题意:给出s个传感器的位置,以及其感应范围.如果某个方向上有墙,则该方向上感应距离减1.现在有w个墙,给出p个物品的位置,问其能被几个 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E = 2.那么找出新增的点和边就可以了.用到了判断线段相 ...
- LA 4127 - The Sky is the Limit (离散化 扫描线 几何模板)
题目链接 非原创 原创地址:http://blog.csdn.net/jingqi814/article/details/26117241 题意:输入n座山的信息(山的横坐标,高度,山底宽度),计算他 ...
- LA 3263 好看的一笔画 欧拉几何+计算几何模板
题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...
- LA 4676 Geometry Problem (几何)
ACM-ICPC Live Archive 又是搞了一个晚上啊!!! 总算是得到一个教训,误差总是会有的,不过需要用方法排除误差.想这题才几分钟,敲这题才半个钟,debug就用了一个晚上了!TAT 有 ...
- 《 iPhone X ARKit Face Tracking 》
欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 本文来自于腾讯Bugly公众号(weixinBugly), 作者:jennysluo,未经作者同意,请勿转载,原文地址:http://mp.w ...
- 多目标跟踪(MOT)论文随笔-SIMPLE ONLINE AND REALTIME TRACKING WITH A DEEP ASSOCIATION METRIC (Deep SORT)
网上已有很多关于MOT的文章,此系列仅为个人阅读随笔,便于初学者的共同成长.若希望详细了解,建议阅读原文. 本文是tracking by detection 方法进行多目标跟踪的文章,在SORT的基础 ...
- 多目标跟踪(MOT)论文随笔-SIMPLE ONLINE AND REALTIME TRACKING (SORT)
网上已有很多关于MOT的文章,此系列仅为个人阅读随笔,便于初学者的共同成长.若希望详细了解,建议阅读原文. 本文是使用 tracking by detection 方法进行多目标跟踪的文章,是后续de ...
随机推荐
- IOS - Foundation和Core Foundation掺杂使用桥接
Foundation和Core Foundation掺杂使用桥接 Toll-Free Bridging 在cocoa application的应用中,我们有时会使用Core Foundation(CF ...
- Myeclipse编写struts程序
说到struts则必须要谈到MVC模式(Model2) 什么是MVC模式.随着应用系统的逐渐增大,系统的业务逻辑复杂度以几何级数方式增加,在这样的情况下,如果还是把所有的处理逻辑都放在JSP页面中,那 ...
- [Android Pro] Android 6.0 Root
reference : http://bbs.gfan.com/android-8001827-1-1.html 2. 刷机和刷入recovery 建议参考 置顶教程: [15年3月31日更新]Nex ...
- zmq-ios framwork
1.附件见zeromq-ios.framework百度网盘/iOS/zmq 2.zeromq-ios.framework解压拖进工程文件 3.objc-zmq见百度网盘/iOS/zmq 4.objc- ...
- ArrayList 和 LinkedList 的区别
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.2.对于随机访问get和set,ArrayList优于LinkedList,因为LinkedList要移动 ...
- YCbCr 编码格式(YUV)---转自Crazy Bingo的博客
YCbCr是DVD.摄像机.数字电视等消费类视频产品中,常用的色彩编码方案. YCbCr 有时会称为 YCC..Y'CbCr 在模拟分量视频(analog component video)中也常被称为 ...
- .net学习笔记----有序集合SortedList、SortedList<TKey,TValue>、SortedDictionary<TKey,TValue>
无论是常用的List<T>.Hashtable还是ListDictionary<TKey,TValue>,在保存值的时候都是无序的,而今天要介绍的集合类SortedList和S ...
- C#的索引器
using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace ...
- Java集合源码学习(三)LinkedList分析
前面学习了ArrayList的源码,数组是顺序存储结构,存储区间是连续的,占用内存严重,故空间复杂度很大.但数组的二分查找时间复杂度小,为O(1),数组的特点是寻址容易,插入和删除困难.今天学习另外的 ...
- 如何减少JS的全局变量污染
A,唯一变量 B,闭包