結果

問題 No.731 等差数列がだいすき
ユーザー aguroshouaguroshou
提出日時 2018-09-07 22:21:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,758 bytes
コンパイル時間 3,069 ms
コンパイル使用メモリ 79,072 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-19 19:56:17
合計ジャッジ時間 3,517 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 << endl;
	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