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 基础计算几何 题解 + 总结的更多相关文章

  1. kuangbin专题十三-基础计算几何

    链接:https://cn.vjudge.net/contest/68968 POJ 2318 TOYS 题意:m个玩具落在n+1个区间,给你玩具的坐标,问每个区间有多少玩具. 思路:叉积的简单应用, ...

  2. kuangbin专题 数论基础 part1?

    线段树专题太难了,那我来做数学吧! 但数学太难了,我......(扯 这两天想了做了查了整理了几道数学. 除了一些进阶的知识,像莫比乌斯反演,杜教筛,min25学不会我跳了,一些基础的思维还是可以记录 ...

  3. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  4. [kuangbin]专题六 最小生成树 题解+总结

    kuangbin专题链接:https://vjudge.net/article/752 kuangbin专题十二 基础DP1 题解+总结:https://www.cnblogs.com/RioTian ...

  5. php面试专题---13、AJAX基础内容考点

    php面试专题---13.AJAX基础内容考点 一.总结 一句话总结: ajax对提升用户速度,缓解服务器压力方面也是很有可取之处的,毕竟传递的数据少了 1.AJAX基础概念? Asynchronou ...

  6. Kuangbin 带你飞-基础计算几何专题 题解

    专题基本全都是模版应用.贴一下模版 平面最近点对 const double INF = 1e16; ; struct Point { int x,y; int type; }; double dist ...

  7. 【kuangbin专题】计算几何_半平面交

    1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...

  8. 【kuangbin专题】计算几何_凸包

    1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...

  9. [kuangbin带你飞]专题十一 网络流个人题解(L题留坑)

    A - ACM Computer Factory 题目描述:某个工厂可以利用P个部件做一台电脑,有N个加工用的机器,但是每一个机器需要特定的部分才能加工,给你P与N,然后是N行描述机器的最大同时加工数 ...

  10. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

随机推荐

  1. linux防火墙使用及配置

    Linux防火墙使用及配置 介绍 防火墙是网络安全的重要组成部分,它帮助保护服务器和计算机免受未经授权访问.恶意攻击和各种网络威胁.在Linux系统中,有一些工具和技术可用于设置和配置防火墙,其中最常 ...

  2. ASR项目实战-交付团队的分工

    对于通常的软件项目,参与角色,比如可以有用户,消费者,产品团队,研发团队(研发团队包括开发和测试),运营团队,运维团队,管理团队. 通常认为,用户,负责购买服务的群体,而消费者,负责使用业务的群体.这 ...

  3. 【笔记-错误】springCloud-alibaba-feign集成sentinel的启动报错

    背景 随着Spring Cloud Alibaba 2.2.0.RELEASE的发布,终于可以使用最新的Spring Boot和Spring Cloud. 现在的环境 依赖 版本 Spring Boo ...

  4. Angular 集成 Material UI 后组件显示不正常 踩坑日记

    在使用了 npm 下载 Material 后, 项目不能正常使用 Material 组件, 随后又使用官方命令使用 Material 组件, 仍然不能正常使用 Material 组件. npm 命令 ...

  5. Deployment控制器

    目录 Deployment控制器 1.deployment及副本数 使用命令生产yaml文件模板 控制器通过什么管理pod? 2.副本数修改方法 3.动态扩展HPA 4.镜像滚动升级及回滚 升级 回退 ...

  6. IO流小结图片

  7. C++篇:第三章_控制结构_知识点大全

    C++篇为本人学C++时所做笔记(特别是疑难杂点),全是硬货,虽然看着枯燥但会让你收益颇丰,可用作学习C++的一大利器 三.控制结构 for循环的结束判定条件是boolean型 只要适当地修改代码,就 ...

  8. GaussDB技术解读:应用无损透明(ALT)

    本文分享自华为云社区<DTCC 2023专家解读丨GaussDB技术解读系列之应用无损透明(ALT)>,作者: GaussDB 数据库. 近日,在第14届中国数据库技术大会(DTCC 20 ...

  9. DTT第7期直播回顾 | 低代码应用构建流程和适用场景,与你想的一样吗?

    摘要:本期直播主题是<揭秘华为云低代码技术微认证>,向开发者们讲述低代码的发展历程,介绍华为低代码平台应用魔方AppCube的开发能力,解读华为低代码的认证和学习体系 本期直播详解 本期直 ...

  10. 标准物模型:设备无缝对接,IOT界的福音

    摘要:信息模型是解决IoT产业发展一系列挑战的关键,在信息模型的基础上可以推进行业标准/架构的统一,进而实现产业链生态的协同. 本文分享自华为云社区<[云驻共创]标准物模型,物联网的福音> ...