QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#830712 | #868. Friendship Circles | Calculatelove | WA | 19ms | 12076kb | C++14 | 2.8kb | 2024-12-24 22:00:03 | 2024-12-24 22:00:05 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 100100;
const double inf = 1e12;
const double eps = 1e-9;
int sgn(double n) {
if (fabs(n) < eps) return 0;
return n > 0 ? +1 : -1;
}
int dcmp(double x, double y) {
return sgn(x - y);
}
struct point {
double x, y;
point() { x = y = 0; }
point(double _x, double _y) : x(_x), y(_y) {}
void input() {
scanf("%lf%lf", &x, &y);
}
};
typedef point vec;
vec operator + (vec a, vec b) { return vec(a.x + b.x, a.y + b.y); }
vec operator - (vec a, vec b) { return vec(a.x - b.x, a.y - b.y); }
vec operator * (vec a, double b) { return vec(a.x * b, a.y * b); }
double cross(vec a, vec b) {
return a.x * b.y - a.y * b.x;
}
double area(vec a, vec b, vec c) {
return cross(b - a, c - a);
}
double get_angle(vec a) {
return atan2(a.y, a.x);
}
struct line {
point st, ed;
double ag;
int id;
line() {}
line(point A, point B) : st(A), ed(B), ag(get_angle(B - A)) {}
};
point line_intersection(line A, line B) {
point p = A.st, q = B.st;
vec x = A.ed - A.st, y = B.ed - B.st;
vec u = q - p;
double t = cross(u, y) / cross(x, y);
return p + x * t;
}
bool ruler(line a, line b) {
double x = a.ag, y = b.ag;
if (!dcmp(x, y)) return sgn(area(a.st, a.ed, b.ed)) < 0;
return x < y;
}
bool on_right(point x, line c) {
return sgn(area(c.st, c.ed, x)) < 0;
}
int n;
point p[N];
line a[N];
point g[N];
int l, r;
int q[N];
void plane_intersection() {
std::sort(a + 1, a + 1 + n, ruler);
l = 1, r = 0;
for (int i = 1; i <= n; i ++) {
if (i > 1 && !dcmp(a[i].ag, a[i - 1].ag)) continue;
while (l < r && on_right(g[r - 1], a[i])) r --;
while (l < r && on_right(g[l], a[i])) l ++;
q[++ r] = i;
if (l < r) g[r - 1] = line_intersection(a[q[r - 1]], a[q[r]]);
}
while (l < r - 1 && on_right(g[r - 1], a[q[l]])) r --;
}
void work() {
scanf("%d", &n), n --;
for (int i = 0; i <= n; i ++) p[i].input();
for (int i = 1; i <= n; i ++) {
point mid = point((p[i].x + p[0].x) / 2.0, (p[i].y + p[0].y) / 2.0);
vec dir = vec(-(p[i].y - p[0].y), (p[i].x - p[0].x));
a[i] = line(mid, mid + dir), a[i].id = i;
}
a[++ n] = line(point(+inf, +inf), point(-inf, +inf)), a[n].id = 0;
a[++ n] = line(point(-inf, +inf), point(-inf, -inf)), a[n].id = 0;
a[++ n] = line(point(-inf, -inf), point(+inf, -inf)), a[n].id = 0;
a[++ n] = line(point(+inf, -inf), point(+inf, +inf)), a[n].id = 0;
plane_intersection();
std::vector<int> ans; ans.clear();
for (int i = l; i <= r; i ++)
if (a[q[i]].id > 0) ans.push_back(a[q[i]].id);
std::sort(ans.begin(), ans.end());
printf("%d ", (int)ans.size());
for (int x : ans) printf("%d ", x);
puts("");
}
int main() {
int T;
scanf("%d", &T);
while (T --)
work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 12044kb
input:
2 4 1 0 3 1 3 -2 7 0 5 0 0 -2 -1 2 2 -2 10 -1 11
output:
2 1 2 3 1 2 3
result:
ok 7 numbers
Test #2:
score: -100
Wrong Answer
time: 19ms
memory: 12076kb
input:
10000 10 132243110 -894263225 -965927366 756806080 -563126858 -401644076 -528090722 -199265042 -184232391 -184423675 -346777300 -583114791 624815460 788278140 543172921 980159251 -143672624 674688477 -393343296 525780596 9 64745555 827730910 -665070184 -152609349 -905275127 -345568169 -949821348 -84...
output:
3 4 5 6 5 1 4 6 7 8 1 1 3 1 2 3 2 2 5 3 1 2 3 6 1 2 3 4 5 6 5 1 2 3 4 9 4 1 2 3 4 6 1 2 3 4 5 9 2 1 2 3 1 4 6 5 2 4 5 6 7 4 1 2 4 5 3 1 2 3 4 1 2 3 6 3 1 6 8 1 1 2 1 2 5 1 3 4 6 7 5 1 2 4 5 6 3 2 3 4 4 1 3 4 7 4 1 3 7 9 3 3 4 5 4 3 4 6 8 5 1 3 4 6 7 3 1 2 3 2 2 3 3 2 5 6...
result:
wrong answer 4961st numbers differ - expected: '3', found: '2'