QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#344857#4368. OilMindevelopedWA 102ms3692kbC++142.8kb2024-03-05 16:19:102024-03-05 16:19:11

Judging History

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

  • [2024-03-05 16:19:11]
  • 评测
  • 测评结果:WA
  • 用时:102ms
  • 内存:3692kb
  • [2024-03-05 16:19:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int eps = 1e-9;
inline bool iszero (double x) {
	return abs (x) <= eps;
}
inline bool eq (double x, double y) {
	return iszero (x - y);
}
inline int sign (double x) {
	if (iszero (x)) return 0;
	else return x > 0 ? 1 : -1;
}

struct vec {
	double x = 0, y = 0;
	vec () = default;
	vec (double px, double py): x(px), y(py) {
		
	} 
	vec (const vec &obj) {
		x = obj.x;
		y = obj.y;
	}
	
	vec operator + (vec b) const {return {x + b.x, y + b.y};} // Addition
	vec operator - (vec b) const {return {x - b.x, y - b.y};} // Subtraction
	vec operator - () const {return {-x, -y};} // Negation
	vec operator * (double k) const {return {x * k, y * k};} // Scalar multiplication
	double operator * (vec b) const {return x * b.x + y * b.y;} // Dot product
	
	double slope () {return y / x;}
};
double cross (vec a, vec b) { // Cross product
	return a.x * b.y - a.y * b.x;
}
bool parallel (vec a1, vec a2, vec b1, vec b2) { // checks if line A1A2 is parallel with B1B2
	return cross (a1 - a2, b1 - b2) == 0; 
}
bool intersect_sl (vec a, vec b, vec p, vec l) { // checks if segment AB intersects with the line on point P with the direction l
	double c1 = cross (p - a, l), c2 = cross (p - b, l);
	return sign (c1 * c2) != -1;
}
bool intersect_ss (vec a1, vec a2, vec b1, vec b2) { // checks if segment A1A2 intersects with B1B2
	double axl = min (a1.x, a2.x), axr = max (a1.x, a2.x), ayl = min (a1.y, a2.y), ayr = max (a1.y, a2.y);
	double bxl = min (b1.x, b2.x), bxr = max (b1.x, b2.x), byl = min (b1.y, b2.y), byr = max (b1.y, b2.y);
	if (sign (axr - bxl) == -1 || sign (axl - bxr) == 1 || sign (ayr - byl) == -1 || sign (ayl - byr) == 1) return false;
	
	return intersect_sl (a1, a2, b1, b1 - b2) && intersect_sl (b1, b2, a1, a1 - a2);
}

const int N = 2005;
int n;
struct node {
	int l, r, y;
} a[N];
struct event {
	double d;
	int t;
	bool operator < (event b) const {
		if (eq (d, b.d)) return t < b.t;
		else return d < b.d;
	}
} b[2 * N];
int main () {
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> a[i].l >> a[i].r >> a[i].y;
		if (a[i].l > a[i].r) swap (a[i].l, a[i].r);
 	}
	int ans = 0;
	for (int i = 1;i <= n;i++) {
		vec p (a[i].l, a[i].y);
		for (int j = 1;j <= n;j++) {
			if (i == j || a[i].y == a[j].y) {
				b[j * 2 - 1].t = b[j * 2].t = 0;
				continue;
			}
			vec q1 (a[j].l, a[j].y), q2 (a[j].r, a[j].y);
			double s1 = 1 / (p - q1).slope (), s2 = 1 / (p - q2).slope ();
			b[j * 2 - 1].d = min (s1, s2);
			b[j * 2 - 1].t = a[j].r - a[j].l;
			b[j * 2].d = max (s1, s2);
			b[j * 2].t = -a[j].r + a[j].l;
		}
		sort (b + 1, b + 2 * n + 1);
		int res = a[i].r - a[i].l;
		ans = max (ans, res);
		for (int j = 1;j <= 2 * n;j++) {
			res += b[j].t;
			ans = max (ans, res);
		}
	}
	cout << ans << endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70

output:

200

result:

ok single line: '200'

Test #2:

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

input:

3
50 60 10
-42 -42 20
25 0 10

output:

25

result:

ok single line: '25'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

1
-100 180 20

output:

280

result:

ok single line: '280'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3504kb

input:

1
-1000000 1000000 1

output:

2000000

result:

ok single line: '2000000'

Test #5:

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

input:

1
-1000000 1000000 1000000

output:

2000000

result:

ok single line: '2000000'

Test #6:

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

input:

1
-1000000 -999999 1000000

output:

1

result:

ok single line: '1'

Test #7:

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

input:

1
1000000 999999 1000000

output:

1

result:

ok single line: '1'

Test #8:

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

input:

2
-1000 0 200
1 1000 200

output:

1000

result:

ok single line: '1000'

Test #9:

score: 0
Accepted
time: 98ms
memory: 3632kb

input:

1000
737368 429284 959063
-548693 513523 43074
243164 -465669 860567
422975 -244747 588631
-136535 -470055 501433
-580596 -269833 22422
476738 -448258 866889
358773 563858 950905
-923261 208187 66835
-295330 444422 360513
-903435 841952 491761
377801 520064 65247
479135 -307498 426574
-794533 -46924...

output:

490622362

result:

ok single line: '490622362'

Test #10:

score: 0
Accepted
time: 102ms
memory: 3604kb

input:

1000
393505 133958 96751
942939 72421 396439
-822694 -718897 366172
-833366 91559 389785
28456 -507666 398767
-178646 616985 288351
465302 236829 106233
-911686 531549 436738
946908 -619546 27459
840101 -51671 27117
904596 -552691 993402
-379495 -968868 996117
-993434 826061 624577
390359 750548 209...

output:

474626777

result:

ok single line: '474626777'

Test #11:

score: 0
Accepted
time: 102ms
memory: 3692kb

input:

1000
91153 -919136 629430
-928593 -340764 946503
-958781 151370 414466
776584 -865178 350581
266056 -678142 180528
855892 -61597 800115
-150759 821898 16625
286683 401612 387028
-104779 -495288 75284
-292434 725113 64163
925796 -886633 920311
-995416 275385 423913
-922152 395549 705834
138194 618689...

output:

482990936

result:

ok single line: '482990936'

Test #12:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

3
10 20 10
20 30 20
10 20 30

output:

20

result:

wrong answer 1st lines differ - expected: '30', found: '20'