QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#300320#7310. Circular SectorsmshcherbaRE 73ms5380kbC++207.9kb2024-01-08 01:26:392024-01-08 01:26:39

Judging History

你现在查看的是最新测评结果

  • [2024-01-08 01:26:39]
  • 评测
  • 测评结果:RE
  • 用时:73ms
  • 内存:5380kb
  • [2024-01-08 01:26:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const db EPS = 1e-9;
const db PI = acos(-1.0);

struct Pt
{
	db x, y;
	Pt operator+(const Pt& p) const
	{
		return {x + p.x, y + p.y};
	}
	Pt operator-(const Pt& p) const
	{
		return {x - p.x, y - p.y};
	}
	Pt operator*(db d) const
	{
		return {x * d, y * d};
	}
	Pt operator/(db d) const
	{
		return {x / d, y / d};
	}
};

db sq(const Pt& p)
{
	return p.x * p.x + p.y * p.y;
}

db abs(const Pt& p)
{
	return sqrt(sq(p));
}

int sgn(db x)
{
	return (EPS < x) - (x < -EPS);
}

Pt perp(const Pt& p)
{
	return {-p.y, p.x};
}

db dot(const Pt& p, const Pt& q)
{
	return p.x * q.x + p.y * q.y;
}

db cross(const Pt& p, const Pt& q)
{
	return p.x * q.y - p.y * q.x;
}

db orient(const Pt& p, const Pt& q, const Pt& r)
{
	return cross(q - p, r - p) / abs(q - p);
}

ostream& operator<<(ostream& os, const Pt& p)
{
	return os << "(" << p.x << "," << p.y << ")";
}

struct Line
{
	Pt n;
	db c;
	Line(const Pt& p, const Pt& q):
		n(perp(q - p)), c(-dot(n, p)) {}
	db side(const Pt& p) const
	{
		return dot(n, p) + c;
	}
	db sqDist(const Pt& p) const
	{
		return side(p) * side(p) / (db)sq(n);
	}
	Pt proj(const Pt& p) const
	{
		return p - n * side(p) / sq(n);
	}
};

bool parallel(const Line& l1, const Line& l2)
{
	return sgn(cross(l1.n, l2.n)) == 0;
}

Pt inter(const Line& l1, const Line& l2)
{
	db d = cross(l1.n, l2.n);
	assert(sgn(d) != 0);
	return perp(l2.n * l1.c - l1.n * l2.c) / d;
}

bool inDisk(const Pt& a, const Pt& b,
	const Pt& p)
{
	return sgn(dot(a - p, b - p)) <= 0;
}

bool onSegment(const Pt& a, const Pt& b,
	const Pt& p)
{
	return sgn(orient(a, b, p)) == 0
		&& inDisk(a, b, p);
}

vector<Pt> circleLine(const Pt& o, db r,
	const Line& l)
{
	db h2 = r * r - l.sqDist(o);
	if (sgn(h2) == -1)
		return {};
	Pt p = l.proj(o);
	if (sgn(h2) == 0)
		return {p};
	Pt h = perp(l.n) * sqrt(h2) / abs(l.n);
	return {p - h, p + h};
}

vector<Pt> circleCircle(const Pt& o1, db r1,
	const Pt& o2, db r2)
{
	Pt d = o2 - o1;
	db d2 = sq(d);
	if (sgn(d2) == 0)
	{
		return {};
	}
	db pd = (d2 + r1 * r1 - r2 * r2) / 2;
	db h2 = r1 * r1 - pd * pd / d2;
	if (sgn(h2) == -1)
		return {};
	Pt p = o1 + d * pd / d2;
	if (sgn(h2) == 0)
		return {p};
	Pt h = perp(d) * sqrt(h2 / d2);
	return {p - h, p + h};
}

bool strictlyIncreasing(db a, db b, db c)
{
	return sgn(a - b) < 0 && sgn(b - c) < 0;
}

struct Sector
{
	Pt o;
	db r, s, theta;
	Pt p1, p2;
};

vector<Sector> sectors;
vector<Line> lines;

struct Event
{
	db x;
	int i, j, k;
	bool operator<(const Event& event) const
	{
		return sgn(x - event.x) < 0;
	}
};

db getY(const PII& ij, db x)
{
	const auto& [i, j] = ij;
	if (j == 0)
	{
		const Line& l = lines[i];
		return -(l.n.x * x + l.c) / l.n.y;
	}
	const Pt& o = sectors[i].o;
	db r = sectors[i].r;
	return o.y + j * sqrt(max((db)0.0, r * r - (x - o.x) * (x - o.x)));
};

struct Comparator
{
	static db x;
	bool operator() (const PII& a, const PII& b) const
	{
		int dy = sgn(getY(a, x) - getY(b, x));
		if (dy != 0)
			return dy < 0;
		return a < b;
	}
};

db Comparator::x;

db getAreaOfCirclePart(db r, db x)
{
	db co = clamp(x / r, (db)-1.0, (db)1.0);
	db alpha = acos(co);
	return (PI - alpha + co * sqrt(1 - co * co)) * r * r / 2;	
}

void solve(int n)
{
	sectors.resize(n);
	lines.clear();
	VI linesBalances;
	for (auto& [o, r, s, theta, p1, p2] : sectors)
	{
		cin >> o.x >> o.y >> r >> s >> theta;
		p1 = {o.x + r * cos(s), o.y + r * sin(s)};
		linesBalances.PB(sgn(cos(s)));
		p2 = {o.x + r * cos(s + theta), o.y + r * sin(s + theta)};
		linesBalances.PB(-sgn(cos(s + theta)));
		lines.PB({o, p1});
		lines.PB({o, p2});
	}
	vector<Event> events;
	FOR(i, 0, n)
	{
		const auto& [o, r, s, theta, p1, p2] = sectors[i];
		if (strictlyIncreasing(s, PI, s + theta)
			|| strictlyIncreasing(s, 3 * PI, s + theta))
		{
			events.PB({o.x - r, i, -1, 1});
			events.PB({o.x - r, i, 1, 1});
		}
		if (strictlyIncreasing(s, 2 * PI, s + theta))
		{
			events.PB({o.x + r, i, -1, -1});
			events.PB({o.x + r, i, 1, -1});
		}
		if (sgn(p1.y - o.y) > 0
			|| (sgn(p1.y - o.y) == 0 && sgn(p1.x - o.x) > 0))
		{
			events.PB({p1.x, i, 1, -1});
		}
		else
		{
			events.PB({p1.x, i, -1, 1});
		}
		if (sgn(p2.y - o.y) > 0
			|| (sgn(p2.y - o.y) == 0 && sgn(p2.x - o.x) < 0))
		{
			events.PB({p2.x, i, 1, 1});
		}
		else
		{
			events.PB({p2.x, i, -1, -1});
		}
		int idxLine = 2 * i;
		for (const Pt& p : {p1, p2})
		{
			assert(sgn(p.x - o.x) != 0);
			bool toLeft = sgn(o.x - p.x) < 0;
			events.PB({o.x, idxLine, 0, toLeft ? 1 : -1});
			events.PB({p.x, idxLine, 0, toLeft ? -1 : 1});
			idxLine++;
		}
		FOR(j, 0, n)
		{
			if (j == i)
				continue;
			const auto& sector = sectors[j];
			if (j < i)
			{
				vector<Pt> cc = circleCircle(o, r, sector.o, sector.r);
				for (const Pt& q : cc)
				{
					// redundant events
					for (int idx : {i, j})
						for (int lu : {-1, 1})
							events.PB({q.x, idx, lu, 0});
				}
			}
			idxLine = 2 * j;
			for (const Pt& p : {sector.p1, sector.p2})
			{
				vector<Pt> cl = circleLine(o, r, lines[idxLine]);
				for (const Pt& q : cl)
				{
					if (onSegment(sector.o, p, q))
					{
						for (int lu : {-1, 1})
							events.PB({q.x, i, lu, 0});
						events.PB({q.x, idxLine, 0, 0});
					}
				}
				idxLine++;
			}
		}
	}
	FOR(i, 0, 2 * n)
	{
		Pt o1 = sectors[i / 2].o;
		Pt pi = i % 2 == 0 ? sectors[i / 2].p1 : sectors[i / 2].p2;
		FOR(j, 0, i)
		{
			if (i / 2 == j / 2 || parallel(lines[i], lines[j]))
				continue;
			Pt o2 = sectors[j / 2].o;
			Pt pj = j % 2 == 0 ? sectors[j / 2].p1 : sectors[j / 2].p2;
			Pt q = inter(lines[i], lines[j]);
			if (onSegment(o1, pi, q)
				&& onSegment(o2, pj, q))
			{
				events.PB({q.x, i, 0, 0});
				events.PB({q.x, j, 0, 0});
			}
		}
	}
	set<PII, Comparator> curves;
	sort(ALL(events));
	db ans = 0;
	for(int idxEvent = 0; ;)
	{
		set<PII> del, add, delAdd;
		int ptr = idxEvent;
		while (ptr < SZ(events) && !(events[idxEvent] < events[ptr]))
		{
			//cerr << "event " << events[ptr].x << " " << events[ptr].i << " " << events[ptr].j << " " << events[ptr].k << endl;
			PII cur = {events[ptr].i, events[ptr].j};
			if (events[ptr].k == -1)
				del.insert(cur);
			else if (events[ptr].k == 1)
				add.insert(cur);
			else
				delAdd.insert(cur);
			ptr++;
		}
		for (const PII& ij : del)
		{
			curves.erase(ij);
		}
		for (const PII& ij : delAdd)
		{
			if (del.count(ij) || add.count(ij) || !curves.count(ij))
				continue;
			curves.erase(ij);
			add.insert(ij);
		}
		if (ptr == SZ(events))
			break;
		db xl = events[idxEvent].x, xr = events[ptr].x;
		Comparator::x = (xl + xr) / 2;
		for (const PII& ij : add)
		{
			curves.insert(ij);
		}
		int bal = 0;
		for (const PII& ij : curves)
		{
			const auto& [i, j] = ij;
			int deltaBal = j == 0 ? linesBalances[i] : -j;
			assert(bal >= 0);
			if (bal == 0 || bal + deltaBal == 0)
			{
				db area;
				if (j == 0)
				{
					area = (getY(ij, xl) + getY(ij, xr)) * (xr - xl) / 2;
				}
				else
				{
					const Pt& o = sectors[i].o;
					db r = sectors[i].r;
					area = j * (getAreaOfCirclePart(r, xr - o.x) - getAreaOfCirclePart(r, xl - o.x)) + o.y * (xr - xl);
				}
				ans -= deltaBal * area;
			}
			bal += deltaBal;
		}
		assert(bal == 0);
		idxEvent = ptr;
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	int n;
	while (cin >> n)
	{
		solve(n);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4104kb

input:

2
-3 -5 5 0.705 0.217
-5 1 4 3.070 4.136
1
-4 -4 1 0.485 2.260
3
4 4 4 4.266 4.673
2 -4 5 0.353 5.565
-2 1 3 3.974 0.207

output:

35.800499999999985
1.129999999999999
106.444931438703563

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 4212kb

input:

2
-2 -1 5 2.250 0.555
-3 0 2 2.189 0.788
2
-5 1 5 0.432 1.643
3 5 5 4.779 2.014
2
2 0 3 4.194 2.691
4 -3 4 0.998 5.376
2
-3 1 4 5.841 2.968
-4 -3 2 4.151 4.029
2
4 -1 5 2.416 2.385
5 0 3 5.315 2.683
2
-2 0 2 3.972 1.255
2 -5 2 0.912 5.211
2
1 0 4 2.826 3.794
-2 -3 1 3.335 3.836
2
-5 4 2 2.496 2.273
...

output:

6.937500000000004
45.712499999999999
43.533920893527551
31.802000000000007
41.886000000000010
12.932000000000000
31.713102368390359
9.889999999999997
3.811499999999999
26.789999999999999
37.187500000000007
10.700500000000000
31.423499999999983
47.664000000000001
25.456499999999998
54.013595092918770...

result:

ok 250 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 4216kb

input:

3
1 -1 5 3.089 5.717
-2 0 2 4.806 3.257
0 -3 2 5.069 3.049
3
-2 -4 2 4.616 2.875
2 -2 4 5.798 3.097
-1 2 1 0.064 5.418
3
-1 1 2 4.105 3.883
0 5 4 1.936 4.292
2 -5 2 0.278 4.486
3
3 -5 5 3.208 4.696
-2 -4 3 3.609 0.906
-2 4 3 3.796 4.334
3
0 -1 1 4.313 0.711
2 -2 1 2.962 0.344
-4 2 5 2.524 3.043
3
-1...

output:

74.157879726552892
33.234999999999999
47.749461461744588
82.280000000000015
38.564999999999998
57.287499999999994
16.887499999999999
30.812466324073270
18.266137364384576
43.264634755237466
42.494217510621972
26.132749175803266
26.404499999999981
30.106728114671803
48.936999999999998
23.139499999999...

result:

ok 166 numbers

Test #4:

score: 0
Accepted
time: 3ms
memory: 4244kb

input:

4
4 3 4 1.727 2.114
-5 3 2 5.010 2.690
-1 1 5 4.078 2.852
1 5 5 2.974 4.884
4
3 4 1 5.626 2.021
2 -4 1 1.241 0.231
4 -4 5 0.323 5.472
-2 5 2 2.648 1.031
4
-1 -1 2 0.156 3.062
2 2 1 1.127 4.124
5 3 5 1.105 5.179
4 2 3 3.363 4.235
4
-2 -3 3 1.013 4.047
0 -5 5 1.829 4.952
-4 0 5 2.029 4.410
3 -1 4 1.40...

output:

89.059592091965925
71.472499999999997
72.359337599729841
126.255569920522035
53.321194904763850
59.877062378554683
47.616876770028668
66.382775434501397
26.793763102702929
32.341499999999996
139.853466960893343
81.663107773503000
102.706053155319367
81.919837964614160
30.252901352145081
88.100998126...

result:

ok 125 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 4196kb

input:

5
-4 -1 4 2.566 3.253
1 -1 2 3.826 4.000
1 2 5 4.113 3.814
-1 -4 2 4.386 3.959
-1 -2 1 5.785 3.937
5
4 2 4 2.417 0.945
-5 -3 3 4.946 5.172
2 -2 2 2.380 0.205
3 3 4 0.766 4.402
-2 4 5 3.442 4.263
5
0 -4 3 5.172 0.603
-4 -5 3 1.321 3.688
-5 1 4 4.363 3.784
-5 -1 4 2.943 2.791
-2 5 3 5.292 5.765
5
-5 -...

output:

79.693585184955936
91.736875590339153
79.436470427630951
77.453260899735838
98.285986593755297
71.089224340747023
7.725500000000002
103.276610901060778
18.876111372247365
83.851724321134284
37.132095585543560
80.144201783696246
100.607500000000002
89.227847271325942
94.924728487345149
24.35600000000...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 4392kb

input:

10
4 4 4 2.043 4.661
0 -2 3 4.728 5.010
1 5 5 0.478 2.500
1 2 4 3.314 2.904
4 -4 5 3.408 5.869
-3 1 5 0.644 2.968
2 0 4 5.532 0.421
2 -3 1 3.492 0.855
-3 -3 5 4.475 4.896
-4 -1 3 0.873 1.815
10
-2 -1 3 4.786 3.714
-4 -3 1 0.155 4.804
-1 -5 3 4.225 2.500
-4 -1 4 5.536 3.954
4 -2 4 5.516 2.204
-3 2 4 ...

output:

217.462255720490418
137.080435157705836
68.280440686838659
81.674905544446773
161.394725071889127
109.854743305694683
88.851098028933592
149.663820955674538
141.260453837597453
150.828583153720501
103.530625418356735
80.042106264194899
135.587222368681950
124.154668157309516
142.296821200933550
136....

result:

ok 50 numbers

Test #7:

score: 0
Accepted
time: 5ms
memory: 4252kb

input:

9
6 -5 6 4.848 5.374
9 4 3 2.135 4.598
8 -4 6 4.443 5.157
0 5 9 3.605 1.226
7 -4 9 1.917 4.657
6 -7 8 3.621 0.258
3 3 4 1.955 5.563
-6 -5 5 3.174 3.778
-10 9 1 5.808 1.214
10
2 0 8 5.479 1.980
-3 -1 10 2.909 0.574
-8 -10 4 1.758 4.039
2 -6 9 5.761 4.499
1 1 2 0.115 0.897
-3 7 6 0.574 4.703
-4 5 6 0....

output:

340.572472199963784
423.411657030425602
188.493590961885076
663.645597577173476
237.474510029904366
435.602263268936781
426.132393829238879
393.573805742597415
204.877572258180152
211.300974323964198
159.246000000000066
84.711314252478488
65.409000000000006
288.210429276220964
53.787499999999994
323...

result:

ok 97 numbers

Test #8:

score: 0
Accepted
time: 7ms
memory: 4240kb

input:

10
-19 46 24 2.749 0.181
25 -35 45 5.805 4.054
-19 41 38 3.066 0.881
39 -15 22 5.876 4.537
-34 23 23 2.975 5.225
-21 -27 36 5.103 1.849
-43 -27 47 1.506 5.692
8 -12 16 2.217 3.584
-39 2 48 3.455 0.978
23 15 42 2.422 2.305
10
41 -31 32 2.089 3.004
-25 22 41 4.804 4.138
-25 32 37 0.576 3.483
-35 36 32...

output:

12052.406264363618902
8029.721602593826901
17841.160242547983216
8905.310278028093308
9364.474299758414418
11342.793063077802799
7432.277263249037787
4958.018309445388695
12178.815954973779299
12163.545508884984883
10152.091787750143340
5644.239555710108107
8047.133278497371066
10406.167543782268694...

result:

ok 50 numbers

Test #9:

score: 0
Accepted
time: 51ms
memory: 5184kb

input:

93
48 -38 55 2.613 0.385
28 53 75 4.293 2.033
88 33 4 3.991 5.533
11 57 6 4.203 2.347
95 71 11 4.082 3.258
-4 39 61 0.466 4.435
-28 -36 75 1.871 5.160
15 -42 18 2.512 3.285
-68 10 25 4.824 3.391
-61 -21 75 1.593 4.869
41 -30 36 0.436 3.602
-100 94 48 4.538 1.943
-1 19 73 1.400 1.056
-43 29 42 2.508 ...

output:

90187.884972230007406
95856.664895293084555
78262.905029265966732
76227.524853917755536
101278.184257133791107
89979.898975388816325
81706.668381386989495

result:

ok 7 numbers

Test #10:

score: 0
Accepted
time: 5ms
memory: 4264kb

input:

4
-46 6 35 0.448 0.600
-38 -36 29 2.044 0.247
87 -33 87 0.139 5.721
-22 -69 56 5.013 5.314
1
-16 11 41 4.997 5.257
10
-80 -53 86 4.687 1.234
-76 -66 64 4.487 2.231
-46 3 39 5.532 4.214
-16 -94 70 1.841 2.220
-66 98 2 4.388 5.140
1 53 15 2.496 0.741
79 79 79 2.831 2.307
-16 10 92 4.938 3.805
-98 65 7...

output:

28820.394977238745923
4418.508499999999913
33061.953463050660503
45686.056434966143570
12072.339439476249026
5985.184023385509136
50770.001552460584207
42946.205898987376713
20200.603769154648035
36999.657973594548821
4337.216000000000349
5574.280499999997119
35395.913270822034974
24095.705148067092...

result:

ok 89 numbers

Test #11:

score: 0
Accepted
time: 22ms
memory: 4340kb

input:

33
-20 33 3 4.628 3.531
-43 10 4 5.952 4.299
49 -32 7 4.523 5.619
31 -15 5 4.429 1.704
50 40 14 4.025 0.773
-44 -14 31 0.113 2.654
-48 -16 2 4.571 2.209
16 14 11 3.296 3.719
34 -7 17 5.346 2.974
6 -45 22 3.532 2.678
-45 -14 33 3.100 1.706
-30 42 43 2.729 3.312
44 16 46 1.660 2.278
40 44 1 3.442 3.05...

output:

15802.283167443203638
21353.722702478004067
17122.857671863148425
17218.507770068499667
20193.954959456968936
18206.933769756455149
16965.217283117544866
19853.432944954362029
18881.619820128114952
12897.384431902642973
17739.729509985405457
20560.400965029872168
21622.473383571283193
21926.10674976...

result:

ok 14 numbers

Test #12:

score: 0
Accepted
time: 73ms
memory: 5380kb

input:

100
7 -66 7 3.504 5.074
-99 4 5 2.346 0.874
-68 93 47 4.684 5.490
89 46 87 4.250 0.385
46 79 87 2.659 5.715
-10 34 60 3.444 1.728
-82 69 83 4.298 2.078
-75 28 57 1.351 3.565
3 69 97 2.213 3.702
31 8 14 2.294 0.927
97 -23 65 1.493 1.414
55 47 45 2.466 4.113
-78 58 91 1.963 5.592
-97 49 84 4.659 1.604...

output:

96546.677629778743722
101085.301215711660916
104860.539882848810521
82685.042951206429279
87897.311215469992021

result:

ok 5 numbers

Test #13:

score: -100
Runtime Error

input:

500
1 -1 2 1.046 1.346
2 2 1 5.506 0.926
0 -2 2 5.468 3.385
0 -1 1 2.747 4.753
1 -2 2 1.805 5.313
2 0 2 1.543 3.123
2 2 2 1.604 0.801
0 -1 2 4.470 5.702
-1 2 2 1.725 4.320
1 1 1 3.526 5.798
2 0 2 2.157 3.678
-2 -2 2 3.575 0.905
-1 0 2 0.226 3.358
-1 0 2 0.655 0.196
-2 -2 1 4.774 0.375
-1 1 2 2.597 1...

output:


result: