- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9735.py
More file actions
Latest commit
43 lines (36 loc) · 1.03 KB
/
Copy path9735.py
File metadata and controls
43 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fromdecimalimport*
getcontext().prec=100
L=Decimal('-1000000')
H=Decimal('1000000')
tor=Decimal('1e-50')
for_inrange(int(input())):
a, b, c, d=map(Decimal, input().split())
deffn(x):
returna*x**3+b*x**2+c*x+d
defbinary(l, h):
whileh-l>tor:
x= (l+h)/2
iffn(x)*fn(l) >0:
l=x
else:
h=x
returnl
ifb**2-3*a*c<0: # 실근이 1개
ans= [binary(L, H)]
else:
s1, s2=sorted([(-b-(b**2-3*a*c)**Decimal('0.5'))/(3*a), (-b+(b**2-3*a*c)**Decimal('0.5'))/(3*a)])
ifround(fn(s1)*fn(s2), 20) >0: # 실근이 1
ans= [binary(L, H)]
elifround(fn(s1), 20) ==0orround(fn(s2), 20) ==0:
# 실근이 2개
ifround(fn(s1), 20) ==0:
ifround(s1, 20) ==round(s2, 20):
ans= [s1]
else:
ans= [s1, binary(s2, H)]
else:
ans= [binary(L, s1), s2]
else: # 실근이 3개
ans= [binary(L, s1), binary(s1, s2), binary(s2, H)]
ans= ['{:.20f}'.format(i) foriinans]
print(*ans)