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. 在Ubuntu机器上使用war包安装Jenkins

    因为一些需求需要迁移之前使用的Jenkins,原来是按照官方文档使用apt方式安装的,这次搬迁后的机器由于默认不通外网(可以通过代理走外网),因此趁此机会,尝试改用war包方式安装 环境目标 系统Ub ...

  2. AntDesignBlazor示例——创建列表页

    本示例是AntDesign Blazor的入门示例,在学习的同时分享出来,以供新手参考. 示例代码仓库:https://gitee.com/known/AntDesignDemo 1. 学习目标 使用 ...

  3. excute方法和submit方法

    区别:   1.参数     execute  Runnable     submit     Callable   2.返回值     execute :void     submit :Futur ...

  4. pinia持久化存储插件-pinia-plugin-persistedstate

    pinia-plugin-persistedstate 丰富的功能可以使 Pinia Store 的持久化更易配置: 与 vuex-persistedstate 相似的 API 所有 Store 均可 ...

  5. 内核模块(.ko) 开发入门

    内核模块时指的是在操作系统内核中动态加载的一段代码,它可以扩展和增强操作系统的功能.内核模块通常用于为操作系统添加新的设备驱动程序.文件系统.网络协议栈等功能. 内核模块是以二进制形式存在的(*.ko ...

  6. Pikachu漏洞靶场 (SSRF服务端请求伪造)

    SSRF(Server-Side Request Forgery:服务器端请求伪造) curl 点击 累了吧,来读一首诗吧 url是这样的: http://192.168.171.30/pikachu ...

  7. P1990-覆盖墙壁

    分情况: \[\left\{ \begin{aligned} & 条形 \left\{ \begin{aligned} 横着\\ 竖着\\ \end{aligned}\right. \\ &a ...

  8. 中秋佳节,程序员教你AI三步成诗,秒变“李白”

    摘要:举杯邀明月,用技术来附庸风雅. 中秋佳节来临之际,你是否开始思念远方的亲朋好友,想为他们送上祝福?又或是与家人团圆赏月之时,希望借一段风雅诗词抒情达意? 华为云的开发者们教你一招,来个技术风的A ...

  9. 手把手教你写一个spring IOC容器

    摘要:spring框架的基础核心和起点毫无疑问就是IOC,IOC作为spring容器提供的核心技术,成功完成了依赖的反转:从主类的对依赖的主动管理反转为了spring容器对依赖的全局控制.今天就带大家 ...

  10. LiteOS内核源码分析:动态内存之Bestfit分配算法

    摘要:本文为大家剖析LiteOS动态内存模块bestfit算法的源代码,包含动态内存的结构体.动态内存池初始化.动态内存申请.释放等. 内存管理模块管理系统的内存资源,它是操作系统的核心模块之一,主要 ...