QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863766 | #3001. Piece of Cake | isWFnoya# | TL | 0ms | 0kb | Python3 | 1.8kb | 2025-01-19 22:05:23 | 2025-01-19 22:05:33 |
answer
import math
from decimal import Decimal, getcontext
# 设置 Decimal 模块的全局精度为 50 位(可以根据需要调整)
getcontext().prec = 50
def C(n, m):
if n <= m:
return Decimal(1.0)
return fac[n] / fac[m] / fac[n - m]
# 定义一个类来表示二维点
class Point:
def __init__(self, x=0.0, y=0.0):
self.x = Decimal(x)
self.y = Decimal(y)
def input(self):
x2, y2 = map(Decimal, input().split())
self.x = x2
self.y = y2
def cross(s, t):
return s.x * t.y - s.y * t.x
maxn = 2550
# 计算组合数 C(n, m)
C = [[Decimal(0)] * (_ + 1) for _ in range(maxn)]
for i in range(0, maxn):
for j in range(0 , i + 1):
if j == 0 or j == i:
C[i][j] = 1
continue
if j <= i - 1:
C[i][j] = C[i - 1][j]
if j > 0:
C[i][j] += C[i - 1][j - 1]
def solve():
# 读取 n 和 k
n, k = map(int, input().split())
n = 2500
p = []
# 输入所有的点
for i in range(n):
point = Point()
# point.input()
p.append(point)
p.reverse() # 反转点列表
ans = Decimal(0.0)
for i in range(n):
for j in range(i + 1, n):
c = cross(p[i], p[j])
cnt = n - (j - i + 1)
if cnt >= k - 2:
ans += c * C[cnt][k - 2]
cnt = j - i - 1
if cnt >= k - 2:
ans -= c * C[cnt][k - 2]
# 输出最终结果,使用 8 位小数
result = ans / 2 / C[n][k]
print(f"{result:.8f}")
if __name__ == "__main__":
T = 1
# T = int(input()) # 可选输入多个测试案例
while T > 0:
solve()
T -= 1
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 3 -5.236334 -8.519438 -9.987847 -0.492878 -9.994555 0.329962