QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#742602 | #3139. Largest Quadrilateral | vwxyz# | TL | 26ms | 11344kb | Python3 | 2.3kb | 2024-11-13 16:53:15 | 2024-11-13 16:53:15 |
Judging History
answer
def Cross_Product(P0,P1,P2):
x0,y0=P0
x1,y1=P1
x2,y2=P2
return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)
def Convex_Hull(points,upper_lower=False):
sorted_points=sorted(points,reverse=True)
upper_convex_hull=[]
lower_convex_hull=[]
for x,y in sorted_points:
if not upper_convex_hull or upper_convex_hull[-1]!=(x,y):
while len(upper_convex_hull)>=2 and Cross_Product(upper_convex_hull[-2],(x,y),upper_convex_hull[-1])>=0:
upper_convex_hull.pop()
upper_convex_hull.append((x,y))
if not lower_convex_hull or lower_convex_hull[-1]!=(x,y):
while len(lower_convex_hull)>=2 and Cross_Product(lower_convex_hull[-2],lower_convex_hull[-1],(x,y))>=0:
lower_convex_hull.pop()
lower_convex_hull.append((x,y))
if upper_lower:
return upper_convex_hull,lower_convex_hull
else:
retu=[]
for x,y in upper_convex_hull+lower_convex_hull[::-1]:
if not retu or retu[-1]!=(x,y) and retu[0]!=(x,y):
retu.append((x,y))
return retu
T=int(input())
for t in range(T):
N=int(input())
X,Y=[],[]
XY=[]
for i in range(N):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
XY.append((x,y))
P=Convex_Hull(XY)
le=len(P)
if le>=4:
def S(i,j,k):
return abs(Cross_Product(P[i%le],P[j%le],P[k%le]))
ans=0
for a in range(le):
b,d=a,a
for c in range(a+2,a+le-1):
while b<=a:
b+=1
while d<=c:
d+=1
while b+1<c and S(a,b,c)<=S(a,b+1,c):
b+=1
while d+1<a+le and S(a,c,d)<=S(a,c,d+1):
d+=1
ans=max(ans,S(a,b,c)+S(a,c,d))
elif le==3:
def S(i,j,k):
return abs(Cross_Product(XY[i],XY[j],XY[k]))
ans=0
a,b,c=[XY.index(p) for p in P]
for i in range(N):
if i in (a,b,c):
continue
ans=max(ans,S(a,b,c)-S(a,b,i))
ans=max(ans,S(a,b,c)-S(b,c,i))
ans=max(ans,S(a,b,c)-S(a,c,i))
else:
ans=0
if ans%2:
ans=str(ans//2)+".5"
else:
ans//=2
print(ans)
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 10708kb
input:
3 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1 4 0 0 1 1 2 2 1 1
output:
3 6 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 10616kb
input:
1 4 0 0 1 0 0 1 3 2
output:
2.5
result:
ok single line: '2.5'
Test #3:
score: 0
Accepted
time: 10ms
memory: 10584kb
input:
3 4 0 0 0 0 0 0 0 0 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1
output:
0 3 6
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 15ms
memory: 10588kb
input:
3 4 0 0 1 1 2 2 1 1 5 0 0 3 3 1 1 4 4 2 2 6 0 0 0 4 4 0 0 0 1 1 1 2
output:
0 0 8
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 26ms
memory: 11344kb
input:
3 6 0 0 8 8 7 9 6 9 5 8 0 99 29 999891293 708205 369022896 771 993004062 999827531 929592437 29458 994968624 999539287 569046020 1943 2200 986643253 11189 5792636 712825 999917190 2482686 272282 43058 665660 10373878 31825 508452623 112 3304 269412577 43817590 3789 999996618 957802194 999902626 9749...
output:
388 996775018731291724.5 965005706567704502.5
result:
ok 3 lines
Test #6:
score: -100
Time Limit Exceeded
input:
3 4096 53819837 441491349 842988334 208694314 834815184 199336081 754579314 871065186 798603871 163346278 881287987 261003199 69176974 629967383 167500703 196776949 934427498 382642646 949669136 517253054 205028216 839840619 904403509 697377307 909983630 685508552 106436006 718191161 704172704 90101...