惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
AI
AI
T
Tor Project blog
Forbes - Security
Forbes - Security
W
WeLiveSecurity
博客园_首页
爱范儿
爱范儿
J
Java Code Geeks
B
Blog
G
GRAHAM CLULEY
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
H
Help Net Security
博客园 - 三生石上(FineUI控件)
C
Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 司徒正美
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Security Latest
Security Latest
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog

Tifa's Blog

随笔 - 关于 C++ 模板的部分特化 随笔 - Miller-Rabin + Pollard-Rho 分解质因子的时间复杂度分析 随笔 - 批量重命名 APK 文件的 Python 脚本 VP 记录 - 2021 CCPC 哈尔滨站 VP 记录 - 2023 ICPC 亚洲区域赛 (南京) VP 记录 - 2023 CCPC 哈尔滨站 VP 记录 - 2023 CCPC 桂林站 VP 记录 - 2021 ICPC 亚洲区域赛 (澳门) 题解 - [Luogu P7486] 「Stoi2031」彩虹 拟阵简介(unfin) 题解 - [Luogu P5824] 十二重计数法 随笔 - C++ 的高维向量 | Tifa's Blog 目录 - 算法竞赛模板 | Tifa's Blog 目录 - 学术垃圾 | Tifa's Blog 比赛记录 - Codeforces Round #842 (Div. 2) 比赛记录 - Hello 2023 | Tifa's Blog 比赛记录 - Codeforces Round #841 (Div. 2) and Divide by Zero 2022 随笔 - C++ 基于标签分发的线性筛 | Tifa's Blog VP 记录 - 2022 ICPC 亚洲区域赛 (杭州) VP 记录 - 2022 ICPC 亚洲区域赛 (济南)
VP 记录 - 2023 ICPC 亚洲区域赛 (网络预选赛 Ⅰ)
Tifa · 2023-10-08 · via Tifa's Blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = ll;
using ull = unsigned long long;
using u64 = ull;
using ldb = long double;

#define for_(i, l, r) for (ll i = (l), i##ed__ = (r); i <= i##ed__; ++i)
#define Rep(i, l, r) for_(i, l, r)

constexpr ldb eps = 1e-6;

struct P {
ldb x, y;

explicit P(ldb x = 0, ldb y = 0): x(x), y(y) {}

bool operator==(const P &r) const {
return abs(x - r.x) < eps && abs(y - r.y) < eps;
}
P operator-(const P &r) const { return P{x - r.x, y - r.y}; }
P operator*(ldb d) const { return P{x * d, y * d}; }
ldb dist2() const { return x * x + y * y; }
ldb dot(const P &r) const { return x * r.x + y * r.y; }
ldb cross(const P &r) const { return x * r.y - y * r.x; }
ldb cross(const P &a, const P &b) const {
return (a - *this).cross(b - *this);
}
};

ldb segdist2(P const &s, P const &e, P const &p) {
if (s == e) return (p - s).dist2();
ldb d = (e - s).dist2(), t = min(d, max(0.l, (p - s).dot(e - s)));
return ((p - s) * d - (e - s) * t).dist2() * 1.l / d / d;
}

bool on_seg(P const &s, P const &e, P const &p) {
return segdist2(s, e, p) < eps;
}

int nxt(int x, int n) { return (++x) == n ? 0 : x; };
bool in_poly(vector<P> const &p, P const &a) {
int cnt = 0, n = p.size();
for_(i, 0, n - 1) {
P const &q = p[nxt(i, n)];
if (on_seg(p[i], q, a)) return true;
cnt ^= ((a.y < p[i].y) - (a.y < q.y)) * a.cross(p[i], q) > 0;
}
return cnt;
}

void solve() {
int n, q;
cin >> n >> q;

vector<P> poly(n);
for (auto &[x, y] : poly) cin >> x >> y;

for_(i, 1, q) {
P p1, p2;
cin >> p1.x >> p1.y >> p2.x >> p2.y;
P c{(p1.x + p2.x) / 2, (p1.y + p2.y) / 2};
ldb r2 = (p1 - p2).dist2() / 4;
if (in_poly(poly, c)) {
cout << r2 / 2 << '\n';
continue;
}
ldb d = 1e4514l;
for_(i, 0, n - 1) d = min(d, segdist2(poly[i], poly[nxt(i, n)], c));
cout << d + r2 / 2 << '\n';
}
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
#ifdef MULCAS
int t = 0;
cin >> t;
for (int i = 0; i < t; ++i)
#endif
solve();
return 0;
}