結果

問題 No.731 等差数列がだいすき
ユーザー aguroshouaguroshou
提出日時 2018-09-07 22:22:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,756 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 79,236 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 19:59:02
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
ll n, m;
ll sum = 0;
ll memo[50][50] = {};
void kansuu(ll num, ll visited[10]) {

}
int main()
{
	long double a, b = 0, c = 0, d = 0;

	//ll a, b = 0, c = 0, d = 0;
	ll l;
	char C[1000][1000] = {};
	long double x[1001] = {}, y[1001] = {}, xhensa[1001] = {}, yhensa[1001] = {}, xave, yave, xkyobun[1001] = {}, ykyobun[1001] = {}, xykyobun[1001] = {}, xkyo = 0, ykyo = 0, xykyo = 0;
	string s;
	ll n, A[1001];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> y[i];
	}
	for (int i = 0; i < n; i++)
	{
		x[i] = i;
	}
	yave = (double)accumulate(y, y + n, 0) / n;
	xave = (double)accumulate(x, x + n, 0) / n;
	for (int i = 0; i < n; i++)
	{
		xhensa[i] = x[i] - xave;
		yhensa[i] = y[i] - yave;
	}
	for (int i = 0; i < n; i++)
	{
		xkyobun[i] = xhensa[i] * xhensa[i];
		ykyobun[i] = yhensa[i] * yhensa[i];
		xykyobun[i] = xhensa[i] * yhensa[i];
	}
	for (int i = 0; i < n; i++)
	{
		xkyo += xkyobun[i];
		ykyo += ykyobun[i];
		xykyo += xykyobun[i];

	}
	xkyo /= n;
	ykyo /= n;
	xykyo /= n;
	a = xykyo / xkyo;
	b = yave - a*xave;
	cout << setprecision(15) << b <<" ";
	cout << setprecision(15) << a << endl;
	long double v = 0;
	for (int i = 0; i < n; i++)
	{
		v += (y[i] - b)*(y[i] - b);
		b += a;
	}


	cout << setprecision(15) << v << endl;


	//cout << sum << endl;
	//cout <<  endl;

	return 0;
}
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
0