题解:P14433 [JOISC 2013] JOI 海报 / JOI Poster

· · 题解

P14433 [JOISC 2013] JOI 海报 题解

题目传送门。

CSP烤炸了,来水篇题解。

题意简述

给定一个 W \times H 的矩形和 N 个点。找到四个点 A, B, C, D,让以 A, B 建立的圆 O_1 完全包含以 C, D 建立的圆 O_2,且两圆均在矩形范围内。求符合要求的方案数。

样例解释

可以证明,在样例 1 中,只有 3 种情况符合要求。

解题思路

注意到 N \le 50,很小,考虑枚举 A, B, C, D。
符合要求的条件有两个,分开讨论。

我们可以预处理每两点间的距离,储存在 dis 数组内,时间复杂度 O(n^2)。
再使用 O(n^4) 的复杂度枚举 A, B, C, D,判断是否符合要求。

注意浮点数误差。 ### 妙妙工具 两点间距离公式:$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$。 ## AC代码 ```cpp #include <bits/stdc++.h> using namespace std; const double eps = 1e-10; int n, w, h, ans; double dis[60][60]; struct point{ int x, y; }p[60]; bool check(int a, int b, int c, int d){ if (dis[a][c] + dis[c][d] < dis[a][b] - eps) if (p[a].x + dis[a][b] <= w + eps && p[a].x - dis[a][b] >= 0 - eps) if (p[a].y + dis[a][b] <= h + eps && p[a].y - dis[a][b] >= 0 - eps) return true; return false; } int main(){ cin >> n >> w >> h; for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++){ int xx = abs(p[i].x - p[j].x), yy = abs(p[i].y - p[j].y); dis[i][j] = sqrt(xx * xx + yy * yy); } for (int a = 1; a <= n; a++) for (int b = 1; b <= n; b++) for (int c = 1; c <= n; c++) for (int d = 1; d <= n; d++){ if (a == b || a == c || a == d || b == c || b == d || c == d) continue; if (check(a, b, c, d)) ans++; } cout << ans << endl; return 0; } ```