Logo
(追記) (追記ここまで)

5649번 - Line of Best Fit 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB108754869.565%

문제

Finding a line of best fit for a set of data is one of fundamental problems in statistics and numerical analysis. The problem can be formulated as follows. Suppose our data consists of a set P of n points in a plane, denoted (x1, y1), (x2, y2), (x3, y3), ..., (xn, yn). Given a line L defined by the linear equation y = ax + b, we say that the error of L with respect to P is the sum of its squared “distance” to the points in P :

\[Error(L,P) = \sum_{i=1}^{n}{(y_i - ax_i - b)^2}\]

The least square approach is to find the line L which minimizes such error. Your task is to write a program to find the values a and b of the line L for a given set of points P.

Figure 1. Example of points and a line of best fit

입력

the first line contains a positive integer n (1 ≤ n ≤ 1,000). The next n lines contain 2 integers: xi and yi in each line. |xi| ≤ 106 and |yi| ≤ 106

출력

The output contains the values a and b in two lines respectively. The numbers must be rounded to 3 decimal places.

제한

예제 입력 1

4
1 6
2 5
3 7
4 10

예제 출력 1

1.400
3.500

힌트

출처

ICPC > Regionals > Asia Pacific > Thailand > 2011 ACM-ICPC Asia Phuket Regional Programming Contest 연습 세션 P2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /