結果
| 問題 | No.731 等差数列がだいすき |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-07 21:49:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,500 ms |
| コード長 | 927 bytes |
| 記録 | |
| コンパイル時間 | 1,036 ms |
| コンパイル使用メモリ | 94,984 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 12:37:49 |
| 合計ジャッジ時間 | 1,955 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <cmath>
static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;
int main() {
int n;
cin >> n;
vector<double> vy, vx;
for (int i = 0; i < n; ++i) {
double k;
cin >> k;
vy.emplace_back(k);
vx.emplace_back(double(i));
}
double xy = 0, x = 0, y = 0, x2 = 0;
for (int i = 0; i < n; ++i) {
xy += vx[i] * vy[i];
x += vx[i];
y += vy[i];
x2 += vx[i] * vx[i];
}
double a = (xy * n - x * y) /(x2 * n - x*x);
double b = (x2 * y - xy * x) / (x2 * n - x*x);
double c = 0;
for (int i = 0; i < n; ++i) {
double k = b + a * i;
c += pow(vy[i]-k, 2);
}
cout << setprecision(16) << b << " " << a << "\n";
cout << c << "\n";
return 0;
}