QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#830692#868. Friendship CirclesCalculateloveWA 19ms12200kbC++142.8kb2024-12-24 21:42:192024-12-24 21:42:20

Judging History

This is the latest submission verdict.

  • [2024-12-24 21:42:20]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 12200kb
  • [2024-12-24 21:42:19]
  • Submitted

answer

#include <bits/stdc++.h>

const int N = 100100;
const double inf = 1000000000000;
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) 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12200kb

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: 11964kb

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'