2 条题解
-
0
G49 向量运算 点线关系【计算几何】
#include<bits/stdc++.h> using namespace std; const int N = 1e4 + 10; struct Point { int x, y; } p[N], o, a; double cross(Point a, Point b, Point c) { // 叉积 return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); } double dis(Point a, Point b) { // 距离 return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { int n, m, ans; double r; while (scanf("%d%d%lf", &o.x, &o.y, &r) != EOF) { n = ans = 0; scanf("%d", &m); while (m--) { scanf("%d%d", &a.x, &a.y); if (dis(a, o) <= r) p[n++] = a; } for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) if (cross(o, p[i], p[j]) >= 0) ++cnt; ans = max(ans, cnt); } printf("%d\n", ans); } return 0; } -
0
#include<bits/stdc++.h> using namespace std; const int N = 1e4 + 10; struct Point { int x, y; } p[N], o, a; double cross(Point a, Point b, Point c) { // 叉积 return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); } double dis(Point a, Point b) { // 距离 return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { int n, m, ans; double r; while (scanf("%d%d%lf", &o.x, &o.y, &r) != EOF) { n = ans = 0; scanf("%d", &m); while (m--) { scanf("%d%d", &a.x, &a.y); if (dis(a, o) <= r) p[n++] = a; } for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) if (cross(o, p[i], p[j]) >= 0) ++cnt; ans = max(ans, cnt); } printf("%d\n", ans); } return 0; }
- 1
信息
- ID
- 1110
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 78
- 已通过
- 19
- 上传者