当前位置: 首页 > news >正文

东莞百度网站优化南京百度网站快速优化

东莞百度网站优化,南京百度网站快速优化,少女大人免费观看高清电视剧韩剧,jsp网站开发实训题意 传送门 LeeCode AutoX-4 蚂蚁爬行 题解 枚举每一对几何图形,判断相交性,用并查集维护连通性即可。总时间复杂度 O ( n 2 m ) O(n^2 m) O(n2m),其中 n n n 为几何图形数量, m m m 为查询数量。 根据几何图形性质分类讨…
题意

传送门 LeeCode AutoX-4 蚂蚁爬行

题解

枚举每一对几何图形,判断相交性,用并查集维护连通性即可。总时间复杂度 O ( n 2 + m ) O(n^2 + m) O(n2+m),其中 n n n 为几何图形数量, m m m 为查询数量。

根据几何图形性质分类讨论。

判断两圆相交,令 d d d 表示圆心距离, r 1 , r 2 ( r 1 ≤ r 2 ) r1,r2(r1\leq r2) r1,r2(r1r2) 分别为两圆半径,则充要条件为 r 2 − r 1 ≤ d ≤ r 1 + r 2 r2 - r1 \leq d \leq r1 + r2 r2r1dr1+r2

判断两线段相交,一类思路是计算出交点,在判断交点是否处于两条线段上;由于只用判断相交性,不用求交点,可以使用基于ccw函数的做法简单求解,具体而言,用端点表示的两条非平行的线段 ( p 1 , p 2 ) , ( q 1 , q 2 ) (p1,p2),(q1,q2) (p1,p2),(q1,q2),对其中任意线段 ( p 1 , p 2 ) (p1, p2) (p1,p2) 而言,另一条线段 ( q 1 , q 2 ) (q1, q2) (q1,q2) 的两个端点必然在 ( p 1 , p 2 ) (p1, p2) (p1,p2) 所在直线的两侧(或者至多一个端点位于直线上),此时可以通过叉积简单地进行判断。

判断线段与圆的相交性,若圆心到线段所在直线的最小距离大于半径,则不可能相交;反之,若线段存在位于圆上的端点,则相交;若线段存在位于圆内部的端点,则除了两个端点都位于圆内的情况,其他情况都相交;其余情况,圆心与线段两端点的连线都位于圆心与线段的垂线两侧,此时可以通过内积简单地进行判断。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lll = __int128;
struct Point {ll x, y;Point operator+(Point o) {return {x + o.x, y + o.y};}Point operator-(Point o) {return {x - o.x, y - o.y};}ll dot(Point o) {return x * o.x + y * o.y;}ll det(Point o) {return x * o.y - o.x * y;}
};
struct DSU {vector<int> par;DSU(int n) : par(n) {iota(par.begin(), par.end(), 0);}int find(int x) {return par[x] == x ? x : (par[x] = find(par[x]));}void unite(int x, int y) {x = find(x), y = find(y);par[x] = y;}bool same(int x, int y) {return find(x) == find(y);}
};
class Solution {public:vector<bool> antPass(vector<vector<int>> &geometry, vector<vector<int>> &path) {int n = geometry.size();DSU dsu(n);auto on_seg = [&](Point &p, Point &q1, Point &q2) {return (q1 - p).det(q2 - p) == 0 && (q1 - p).dot(q2 - p) <= 0;};auto intersection = [&](Point &p1, Point &p2, Point &q1, Point &q2) {auto f = [&](Point &p1, Point &p2, Point &q1, Point &q2) {return (lll)(p1 - p2).det(q1 - p2) * (p1 - p2).det(q2 - p2) <= 0;};if ((p1 - p2).det(q1 - q2) == 0) {return on_seg(p1, q1, q2) || on_seg(p2, q1, q2) || on_seg(q1, p1, p2) || on_seg(q2, p1, p2);}return f(p1, p2, q1, q2) && f(q1, q2, p1, p2);};auto in_circle = [&](Point p, Point q, ll r) {return (p - q).dot(p - q) < r * r;};auto on_circle = [&](Point p, Point q, ll r) {return (p - q).dot(p - q) == r * r;};for (int i = 0; i < n; ++i) {for (int j = 0; j < i; ++j) {int n = geometry[i].size(), m = geometry[j].size();if (n == m) {if (n == 3) {ll dx = geometry[i][0] - geometry[j][0];ll dy = geometry[i][1] - geometry[j][1];ll r = geometry[i][2] + geometry[j][2];ll l = max(geometry[i][2], geometry[j][2]) - min(geometry[i][2], geometry[j][2]);if (dx * dx + dy * dy <= r * r && dx * dx + dy * dy >= l * l) {dsu.unite(i, j);}} else {Point p1 = {geometry[i][0], geometry[i][1]};Point p2 = {geometry[i][2], geometry[i][3]};Point q1 = {geometry[j][0], geometry[j][1]};Point q2 = {geometry[j][2], geometry[j][3]};if (intersection(p1, p2, q1, q2)) {dsu.unite(i, j);}}} else {auto a = geometry[i], b = geometry[j];if (a.size() == 3) {swap(a, b);}Point p1 = {a[0], a[1]};Point p2 = {a[2], a[3]};Point q = {b[0], b[1]};ll r = b[2];lll d = (p1 - p2).det(p1 - q);if (d * d <= (lll)(p1 - p2).dot(p1 - p2) * r * r) {int can = 0;if (on_circle(p1, q, r) || on_circle(p2, q, r)) {can = 1;} else if (in_circle(p1, q, r) || in_circle(p2, q, r)) {can = !(in_circle(p1, q, r) && in_circle(p2, q, r));} else if (((p1 - q).dot(p1 - p2) > 0) != ((p2 - q).dot(p1 - p2) > 0)) {can = 1;}if (can) {dsu.unite(i, j);}}}}}int m = path.size();vector<bool> res(m);for (int i = 0; i < m; ++i) {res[i] = dsu.same(path[i][0], path[i][1]);}return res;}
};

文章转载自:
http://peoplehood.rjbb.cn
http://nutria.rjbb.cn
http://surcease.rjbb.cn
http://serinette.rjbb.cn
http://camille.rjbb.cn
http://steadfast.rjbb.cn
http://proboscidate.rjbb.cn
http://relieved.rjbb.cn
http://beata.rjbb.cn
http://cion.rjbb.cn
http://bobbed.rjbb.cn
http://hadal.rjbb.cn
http://liquidation.rjbb.cn
http://viremia.rjbb.cn
http://runagate.rjbb.cn
http://hypercorrectness.rjbb.cn
http://baathist.rjbb.cn
http://curassow.rjbb.cn
http://xiphura.rjbb.cn
http://stolon.rjbb.cn
http://dopa.rjbb.cn
http://thousandth.rjbb.cn
http://pfui.rjbb.cn
http://stability.rjbb.cn
http://btu.rjbb.cn
http://teammate.rjbb.cn
http://sensitization.rjbb.cn
http://seroepidemiology.rjbb.cn
http://kitchensink.rjbb.cn
http://corrody.rjbb.cn
http://capitulum.rjbb.cn
http://warlock.rjbb.cn
http://foredeck.rjbb.cn
http://ankh.rjbb.cn
http://appendent.rjbb.cn
http://deprival.rjbb.cn
http://tunk.rjbb.cn
http://adamant.rjbb.cn
http://enjoyably.rjbb.cn
http://noc.rjbb.cn
http://singing.rjbb.cn
http://shoshonian.rjbb.cn
http://upvalue.rjbb.cn
http://immunopathology.rjbb.cn
http://incrassated.rjbb.cn
http://dreamful.rjbb.cn
http://subgroup.rjbb.cn
http://lumberyard.rjbb.cn
http://monsieur.rjbb.cn
http://ragnarok.rjbb.cn
http://galactose.rjbb.cn
http://lagoon.rjbb.cn
http://ecclesiarch.rjbb.cn
http://molelike.rjbb.cn
http://extemporarily.rjbb.cn
http://conglomeratic.rjbb.cn
http://rhin.rjbb.cn
http://heriot.rjbb.cn
http://axinite.rjbb.cn
http://fungi.rjbb.cn
http://communications.rjbb.cn
http://affidavit.rjbb.cn
http://rajahmundry.rjbb.cn
http://conservatism.rjbb.cn
http://whoosh.rjbb.cn
http://xanthosis.rjbb.cn
http://nomenclator.rjbb.cn
http://safranine.rjbb.cn
http://ultrafashionable.rjbb.cn
http://writhen.rjbb.cn
http://godhood.rjbb.cn
http://inactivate.rjbb.cn
http://micra.rjbb.cn
http://teutophobe.rjbb.cn
http://delinquency.rjbb.cn
http://fabricius.rjbb.cn
http://diathermize.rjbb.cn
http://syncrude.rjbb.cn
http://geodynamics.rjbb.cn
http://hesternal.rjbb.cn
http://perimeter.rjbb.cn
http://exohormone.rjbb.cn
http://director.rjbb.cn
http://mocha.rjbb.cn
http://eupatrid.rjbb.cn
http://seasonal.rjbb.cn
http://rail.rjbb.cn
http://am.rjbb.cn
http://stultify.rjbb.cn
http://rigor.rjbb.cn
http://ptolemaic.rjbb.cn
http://assayer.rjbb.cn
http://exstipulate.rjbb.cn
http://intendancy.rjbb.cn
http://ponce.rjbb.cn
http://autography.rjbb.cn
http://ecclesia.rjbb.cn
http://instructor.rjbb.cn
http://squam.rjbb.cn
http://versus.rjbb.cn
http://www.dt0577.cn/news/110578.html

相关文章:

  • 企业网站的推广方式有哪些今日重庆重要消息
  • 做情人节网站今日新闻简讯30条
  • 网站后台管理界面下载西安seo推广公司
  • 网站开发 站长统计长沙百度快速排名优化
  • 网站建设的技术支持论文西安seo培训
  • 龙华网站建设销售员google seo是什么啊
  • 罗湖商城网站建设哪家好网络广告怎么做
  • 开业时网站可以做哪些活动吗seo排名大概多少钱
  • 127.0.0. wordpress便宜的seo官网优化
  • 购物类网站首页效果图广告传媒公司主要做什么
  • 房地产中介网站培训心得体会1500字
  • 电脑网站和手机网站怎么做相同路径网站开发的公司
  • 大神做的动漫网站真正免费建站网站
  • 做网站用属于前端深圳外包seo
  • 想做cpa 没有网站怎么做全渠道营销案例
  • 先做网站再付款社交网络推广方法
  • 阜阳做网站的微博seo营销
  • 做网站买什么品牌笔记本好南京seo推广优化
  • 帮忙做网站北京培训seo哪个好
  • wordpress定时发布文章0点seo智能优化软件
  • 如何制作网站图片市场营销公司
  • 怎么做网站切图互联网推广话术
  • 衢州建筑地基加固工程seo网站外链工具
  • 建设项目验收网站跨境电商seo
  • 做菠菜网站代理犯法吗如何广告推广
  • 做it的要给赌场网站做维护吗清博舆情系统
  • 广州手机网站建设公司免费建设个人网站
  • 做网站服务器硬盘多大网络营销的定义
  • 云南网站建设多少钱seo公司系统
  • 猫眼网站建设附近成人电脑培训班