求助第六题

5 views
Skip to first unread message

韦锦鹏

unread,
Jan 2, 2019, 8:12:45 PM1/2/19
to cs10...@googlegroups.com

total,days=map(int,input().split())
data = [[int(x) for x in input().split()] for i in range(total)]
def get_diff(A, B):
    s = 0
    for i in range(len(A)):
        s += A[i] - B[i]
    return s / len(A)

def get_stdv(A, B):
    s = 0
    for i in range(len(A)):
        s += A[i] - B[i]
    mean = s / len(A)
    new = 0
    for i in range(len(A)):
        new += (A[i] - B[i] - mean) ** 2
    return math.sqrt(new / len(A))

def evaluate(linex, liney):
    days = len(linex)
    income = 0
    for day in range(3, days-1):
        diff = get_diff(linex[:day], liney[:day])
        stdv = get_stdv(linex[:day], liney[:day])
        A = linex[day+1] - linex[day]
        B = liney[day+1] - liney[day]
        get = abs(linex[day] - liney[day] - diff) // stdv
        income += abs(A * get) + abs(B * get)
    return income

best = (0,1)
bestIncome = 0
for i in range(total):
    for j in range(i+1,total):
        curr = evaluate(data[i], data[j])
        if curr > bestIncome:
            bestIncome = curr
            best = (i,j)
print(int(best[0]+1),int(best[1]+1),int(bestIncome))


Reply all
Reply to author
Forward
0 new messages