[kuangbin] 专题13 基础计算几何 题解 + 总结
kuangbin带你飞:点击进入新世界
[kuangbin] 专题7 线段树 题解 + 总结:https://www.cnblogs.com/RioTian/p/13413897.html
kuangbin专题十二 基础DP1 题解+总结:https://www.cnblogs.com/RioTian/p/13110438.html
kuangbin专题六 最小生成树 题解+总结:https://www.cnblogs.com/RioTian/p/13380764.html
[kuangbin]专题九 连通图 题解+总结 : https://www.cnblogs.com/RioTian/p/13395039.html
计算几何分类blog:https://www.cnblogs.com/RioTian/category/1852545.html
总结
1、TOYS POJ - 2318
题目链接: Click Here
题目大意: 有一个方盒子 有N个板隔开 分成N+1个区域
又给了M个玩具的坐标 问你每个区域内(不能恰好在区域内)的玩具有几个(忽略玩具体积)
解题思路: 每相邻的两个板看成两个向量 分别求其与其中一点和玩具坐标的叉积 如果两叉积的乘积<0 就说明这个玩具坐标点在一个板的右边 一个板的左边
因为数据量比较大 可以把板和方盒的两边记录下来 然后二分 道理是一样的
AC代码:
Code
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
const int N = 5000 + 10;
int num[N], x[N], y[N];
struct node {
double x, y;
} pu[N], pl[N], q;
int n, m, f;
int mul(node p1, node p2, node p3) {
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
void Bisearch(node x) {
int l = 0, r = n + 1, ans;
while (l <= r) {
int mid = (l + r) >> 1;
if (mul(x, pu[mid], pl[mid]) < 0)
ans = mid, r = mid - 1;
else
l = mid + 1;
}
num[ans - 1]++;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int x1, x2, y1, y2;
while (cin >> n) {
if (n == 0) break;
ms(num, 0);
cin >> m >> x1 >> y1 >> x2 >> y2;
// scanf("%d %d %d %d %d", &m, &x1, &y1, &x2, &y2);
pu[0].x = x1, pu[0].y = y1;
pl[0].x = x1, pl[0].y = y2;
for (int i = 1; i <= n; ++i) {
// scanf("%d %d", &pu[i].x, &pl[i].x);
cin >> pu[i].x >> pl[i].x;
pu[i].y = y1, pl[i].y = y2;
}
pu[n + 1].x = x2, pu[n + 1].y = y1;
pl[n + 1].x = x2, pl[n + 1].y = y2;
for (int i = 0; i < m; i++) {
// scanf("%d %d", &q.x, &q.y);
cin >> q.x >> q.y;
Bisearch(q);
}
if (f == 1) printf("\n");
f = 1;
for (int i = 0; i <= n; i++) printf("%d: %d\n", i, num[i]);
}
}
另一种写法
Code
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5e3 + 5;
const db eps = 1e-10;
int dcmp(db x) {
if(fabs(x) < eps) {
return 0;
}
return x > 0? 1: -1;
}
struct Point {
double x, y;
Point(double xx = 0, double yy = 0) : x(xx), y(yy) {}
void input() {
scanf("%lf%lf", &x, &y);
}
Point operator-(const Point a) {
return Point(x - a.x, y - a.y);
}
db cross(const Point a) {
return x * a.y - y * a.x;
}
};
typedef Point Vector;
struct Line {
Point s, e;
Line() {}
Line(Point s, Point e) : s(s), e(e) {}
int toLeftTest(Point p) {
if((e - s).cross(p - s) > 0) return 1;
else if((e - s).cross(p - s) < 0) return -1;
return 0;
}
};
int n, m;
Line line[maxn];
Point point[maxn];
int ans[maxn];
void solve() {
for(int i = 1; i <= m; ++i) {
int l = 0, r = n + 1;
int mid = (l + r) >> 1;
while(l + 1 < r) {
if(line[mid].toLeftTest(point[i]) > 0) {
r = mid;
} else {
l = mid;
}
mid = (l + r) >> 1;
}
ans[l]++;
}
for(int i = 0; i <= n; ++i) {
printf("%d: %d\n", i, ans[i]);
}
printf("\n");
}
int main() {
while(scanf("%d", &n) != EOF && n) {
memset(ans, 0, sizeof(ans));
scanf("%d", &m);
db xl, yl, xr, yr;
scanf("%lf%lf%lf%lf", &xl, &yl, &xr, &yr);
line[0].s = Point(xl, yr);
line[0].e = Point(xl, yl);
line[n + 1].s = Point(xr, yr);
line[n + 1].e = Point(xr, yl);
for(int i = 1; i <= n; ++i) {
db u, l;
scanf("%lf%lf", &u, &l);
line[i].s = Point(l, yr);
line[i].e = Point(u, yl);
}
for(int i = 1; i <= m; ++i) {
scanf("%lf%lf", &point[i].x, &point[i].y);
}
solve();
}
return 0;
}
2、Toy Storage POJ - 2398
题目链接:Click Here
与 POJ 2318 类似,不同的是这次给定的线段是乱序的,因此先要排序。输出也不同,改一下即可。
Code
// Author : RioTian
// Time : 20/10/21
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5e3 + 5;
const db eps = 1e-10;
int dcmp(db x) {
if (fabs(x) < eps) {
return 0;
}
return x > 0 ? 1 : -1;
}
struct Point {
double x, y;
Point(double xx = 0, double yy = 0) : x(xx), y(yy) {}
void input() { scanf("%lf%lf", &x, &y); }
bool operator<(const Point &a) const {
return (!dcmp(x - a.x)) ? dcmp(y - a.y) < 0 : x < a.x;
}
Point operator-(const Point a) { return Point(x - a.x, y - a.y); }
db cross(const Point a) { return x * a.y - y * a.x; }
};
typedef Point Vector;
struct Line {
Point s, e;
Line() {}
Line(Point s, Point e) : s(s), e(e) {}
bool operator<(const Line &a) const { return s < a.s; }
int toLeftTest(Point p) {
if ((e - s).cross(p - s) > 0)
return 1;
else if ((e - s).cross(p - s) < 0)
return -1;
return 0;
}
};
int cmp(Line a, Line b) { return a.s < b.s; }
int n, m;
Line line[maxn];
Point point[maxn];
int ans[maxn];
int cnt[maxn];
void solve() {
for (int i = 1; i <= m; ++i) {
int l = 0, r = n + 1;
int mid = (l + r) >> 1;
while (l + 1 < r) {
if (line[mid].toLeftTest(point[i]) > 0) {
r = mid;
} else {
l = mid;
}
mid = (l + r) >> 1;
}
ans[l]++;
}
int max_size = 0;
for (int i = 0; i <= n; ++i) {
if (ans[i]) {
cnt[ans[i]]++;
max_size = max(max_size, ans[i]);
}
}
printf("Box\n");
for (int i = 1; i <= max_size; ++i) {
if (cnt[i]) {
printf("%d: %d\n", i, cnt[i]);
}
}
}
int main() {
while (scanf("%d", &n) != EOF && n) {
memset(ans, 0, sizeof(ans));
memset(cnt, 0, sizeof(cnt));
scanf("%d", &m);
db xl, yl, xr, yr;
scanf("%lf%lf%lf%lf", &xl, &yl, &xr, &yr);
line[0].s = Point(xl, yr);
line[0].e = Point(xl, yl);
line[n + 1].s = Point(xr, yr);
line[n + 1].e = Point(xr, yl);
for (int i = 1; i <= n; ++i) {
db u, l;
scanf("%lf%lf", &u, &l);
line[i].s = Point(l, yr);
line[i].e = Point(u, yl);
}
sort(line + 1, line + 1 + n); // 要对线段排序
for (int i = 1; i <= m; ++i) {
scanf("%lf%lf", &point[i].x, &point[i].y);
}
solve();
}
return 0;
}
[kuangbin] 专题13 基础计算几何 题解 + 总结的更多相关文章
- kuangbin专题十三-基础计算几何
链接:https://cn.vjudge.net/contest/68968 POJ 2318 TOYS 题意:m个玩具落在n+1个区间,给你玩具的坐标,问每个区间有多少玩具. 思路:叉积的简单应用, ...
- kuangbin专题 数论基础 part1?
线段树专题太难了,那我来做数学吧! 但数学太难了,我......(扯 这两天想了做了查了整理了几道数学. 除了一些进阶的知识,像莫比乌斯反演,杜教筛,min25学不会我跳了,一些基础的思维还是可以记录 ...
- [kuangbin带你飞]专题一 简单搜索 题解报告
又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...
- [kuangbin]专题六 最小生成树 题解+总结
kuangbin专题链接:https://vjudge.net/article/752 kuangbin专题十二 基础DP1 题解+总结:https://www.cnblogs.com/RioTian ...
- php面试专题---13、AJAX基础内容考点
php面试专题---13.AJAX基础内容考点 一.总结 一句话总结: ajax对提升用户速度,缓解服务器压力方面也是很有可取之处的,毕竟传递的数据少了 1.AJAX基础概念? Asynchronou ...
- Kuangbin 带你飞-基础计算几何专题 题解
专题基本全都是模版应用.贴一下模版 平面最近点对 const double INF = 1e16; ; struct Point { int x,y; int type; }; double dist ...
- 【kuangbin专题】计算几何_半平面交
1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...
- 【kuangbin专题】计算几何_凸包
1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...
- [kuangbin带你飞]专题十一 网络流个人题解(L题留坑)
A - ACM Computer Factory 题目描述:某个工厂可以利用P个部件做一台电脑,有N个加工用的机器,但是每一个机器需要特定的部分才能加工,给你P与N,然后是N行描述机器的最大同时加工数 ...
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
随机推荐
- 用友NC产品接口开发,通过轻易云数据集成平台快速调用
通过用友NC产品的 UAP V63平台.插件相关处理.相关业务逻辑处理课程目标与要求课程内容课程目标与要求业务逻辑处理外部系统信息设置节点新建外部系统默认匹配规则:仅按对照表:外部系统数据与UAP.接 ...
- 【Android】实现连接SQLite并尝试进行增删改查
- Net 高级调试之十一:托管堆布局架构和对象分配机制
一.简介 今天是<Net 高级调试>的第十一篇文章,这篇文章来的有点晚,因为,最近比较忙,就没时间写文章了.现在终于有点时间,继续开始我们这个系列.这篇文章我们主要介绍托管堆的架构,对象的 ...
- 解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题
问题描述 在使用tensorflow2.0时,遇到了这个问题: AttributeError: module 'tensorflow' has no attribute 'get_default_gr ...
- SpringBoot-Validation优雅实现参数校验
1.是什么? 它简化了 Java Bean Validation 的集成.Java Bean Validation 通过 JSR 380,也称为 Bean Validation 2.0,是一种标准化的 ...
- 推荐给前端开发的 5 款 Chrome 扩展 🚀
大家好,我是 dom 哥.这是我关于 Chrome 扩展开发的系列文章,感兴趣的可以 点个小星星. 工欲善其事,必先利其器.Chrome 可能是前端开发中使用最多的浏览器.在日常开发中,下列几款 Ch ...
- 华企盾DSC客户端连接服务器正常,控制台找不到客户端
1.首先客户端查一下策略状态,看一下客户端在哪个组,是否在回收站,或者无策略组: 2.查看一下数据库的CLIENT_GROUP_TABLE_表中是否有查出来的组,CLIENT_GROUP_TABLE_ ...
- linux rz/sz 拖动文件上传
不需要第三方上传文件直接 rz上传 拖动.以及 sz下载文件 多舒服 那么 他来了 安装与使用 yum安装 yum -y install lrzsz 使用上传文件,执行命令rz,会跳出文件选择窗口,选 ...
- 春秋云镜 - CVE-2022-28060
Victor CMS v1.0 /includes/login.php 存在sql注入 找到页面的登录框,看介绍应该是post类型的表单注入. 上sqlmap用原本的梭发现ctf的那个表是空的,换用- ...
- export详解
linux下export命令详解 export:将自定义变量设定为系统环境变量(当前shell中有效) 功能说明:设置或显示环境变量. 语 法:export [-fnp][变量名称]=[变量设置值] ...