[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 ...
随机推荐
- 图文剖析 big.js 四则运算源码
big.js,一个小型.快速的用于任意精度的十进制算术的JavaScript 库. big.js 用于解决平常项目中进行算术运算时精度丢失引起的结果不准确的问题.和 big.js 类似的两个库 big ...
- 管易云与网易互客对接集成发货单查询2.0=>编辑订单
管易云与网易互客对接集成发货单查询2.0=>编辑订单 对接源平台:管易云 管易云是金蝶旗下专注提供电商企业管理软件服务的子品牌,先后开发了C-ERP.EC-OMS.EC-WMS.E店管家.BBC ...
- 【Javaweb】五(Service类)
一般Spring项目中处理业务的层为Service层,称为业务层.目前常见的风格有: 写法:Service层=Service接口+ServiceImpl实现类 AdminServiceImpl.jav ...
- [ABC309G] Ban Permutation
Problem Statement Find the number, modulo $998244353$, of permutations $P=(P_1,P_2,\dots,P_N)$ of $( ...
- 01 MyBatis第一个应用程序
1.MyBatis是什么? mybatis是一个基于java的持久层框架. 2.什么是持久化 数据由瞬态状态变为持久状态. 3.持久层: 完成持久化工作的代码块. -- DAO层,将数据存到数据库 4 ...
- .NET微信网页开发之通过UnionID机制解决多应用用户帐号统一问题
背景 随着公司微信相关业务场景的不断拓展,从最初的一个微信移动应用.然后发展成微信公众号应用.然后又有了微信小程序应用.但是随着应用的拓展,如何保证相同用户的微信用户在不同应用中登录的同一个账号呢?今 ...
- 8、switch语句
1.switch语句:"开关" switch是一个条件语句,它计算表达式并将其与可能匹配的列表进行比较,并根据匹配执行代码块.它可以被认为是一种惯用的方式来写多个if else子句 ...
- 小程序优化:第三方SDK过大解决方案
[前言] 小程序开发中,有时会遇到下面这种情况,项目目录中存放过大的js包,会被警告影响手机端性能,同时让开发编译启动变得很慢.慢是其次,单是影响性能这一点,就需要解决一下. [云资源] 将项目js包 ...
- 华企盾DSC 恢复密钥需要提供信息
1.win.ini 2.5097目录复制一份 3.c:\windows\system32\autheninfoset.cfg (64位系统:c:\windows\syswow64\autheninfo ...
- Vue学习笔记-指令