跳到正文

个人记录

深渊统计

AstaVenti_约 7 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 7 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
using db=double;
typedef long long ll;

vector<pair<string,tuple<db,db,db>>>a(42);
vector<db>ave(42);
db bhat,ahat,xbar,ybar,fz,bfm,rfm,ry;

void fout(string x,ll len){
	ll sz=x.size(),l=(len-sz)/2,r=len-sz-l;
	for(ll i=1;i<=l;i++)cout<<" ";
	cout<<x;
	for(ll i=1;i<=r;i++)cout<<" ";
}

string itos(ll x){
	string s;
	bool f=0;
	if(x<0)f=1,x=-x;
	while(x>0){
		s+=(x%10)+'0';
		x/=10;
	}
	reverse(s.begin(),s.end());
	if(f)s='-'+s;
	return s;
}

int main(){
//	freopen("Abyss statistics.txt","w",stdout);
	ll n=41;
	a[1]={"1.0~1.1",{901837,996393,1470605}};
	a[2]={"1.2",{1179326,996393,1470605}};
	a[3]={"1.3~1.4",{1109954,766456,1470605}};
	a[4]={"1.5",{1109954,720468,1084571}};
	a[5]={"1.6",{1109954,1456266,1250014}};
	a[6]={"2.0",{1800578,2452659,2359527}};
	a[7]={"2.1",{1425496,2305421,3277741}};
	a[8]={"2.2",{1683957,2688648,2665471}};
	a[9]={"2.3",{2135146,1716861,3166821}};
	a[10]={"2.4",{2874415,2789899,3308861}};
	a[11]={"2.5",{2430433,1925824,1746991}};
	a[12]={"2.6",{1479883,950405,1250014}};
	a[13]={"2.7",{2081163,2452659,3188951}};
	a[14]={"2.8",{1604752,1767086,2606621}};
	a[15]={"3.0",{2180576,3071876,3438521}};
	a[16]={"3.1",{1680860,2434172,2773001}};
	a[17]={"3.2",{2930149,3053390,3660361}};
	a[18]={"3.3",{3134578,2240276,3577171}};
	a[19]={"3.4",{3146278,2745597,3466251}};
	a[20]={"3.5",{1955536,3335432,3411706}};
	a[21]={"3.6",{2930149,3399039,3689006}};
	a[22]={"3.7",{1771245,3605041,3327601}};
	a[23]={"3.8",{2804925,3553541,3050301}};
	a[24]={"4.0",{2750302,3193037,3493981}};
	a[25]={"4.1",{2978036,3347538,3979256}};
	a[26]={"4.2",{3704894,3682292,3333513}};
	a[27]={"4.3",{3747865,3636567,4570767}};
	a[28]={"4.4",{3566150,3090036,3688091}};
	a[29]={"4.5",{4043151,3912229,4187321}};
	a[30]={"4.6",{3835673,3448789,3944822}};
	a[31]={"4.7",{3544192,4468445,4619065}};
	a[32]={"4.8",{5110724,4449353,4409072}};
	a[33]={"5.0",{4270294,4597197,5629192}};
	a[34]={"5.1A",{4974438,4315154,4783427}};
	a[35]={"5.1B",{4674609,4789555,5756750}};
	a[36]={"5.2",{5834573,4387850,4825022}};
	a[37]={"5.3",{6732528,4696854,4991402}};
	a[38]={"5.4A",{6102557,5998085,6364037}};
	a[39]={"5.4B",{5057472,6884242,8185899}};
	a[40]={"5.5",{6287769,7840965,7498313}};
	a[41]={"5.6A",{7584315,5446188,5748511}};
	for(ll i=1;i<=n;i++){
		ave[i]=(get<0>(a[i].second)+get<1>(a[i].second)+get<2>(a[i].second))/3;
		xbar+=i,ybar+=ave[i];
	}
	xbar/=n,ybar/=n;
	for(ll i=1;i<=n;i++){
		fz+=(i-xbar)*(ave[i]-ybar);
		bfm+=(i-xbar)*(i-xbar);
		ry+=(ave[i]-ybar)*(ave[i]-ybar);
	}
	bhat=fz/bfm,ahat=ybar-bhat*xbar;
	cout<<"              ^\n";
	cout<<"经验回归方程:y="<<bhat<<"x";
	if(ahat>0)cout<<"+";
	cout<<ahat<<"\n\n";
	cout<<"样本相关系数:r="<<fz/(sqrt(bfm)*sqrt(ry))<<"\n\n";
	cout<<"┌————————————————————————————————————————————————————————————————————┐\n";
	cout<<"│  版本   |  12-1   |  12-2   |  12-3   |实际均值 |预测均值 |  残差  │\n";
	cout<<"├————————————————————————————————————————————————————————————————————│\n";
	for(ll i=1;i<=n;i++){
		cout<<"│";fout(a[i].first,9);
		string r1=itos(get<0>(a[i].second)),r2=itos(get<1>(a[i].second)),r3=itos(get<2>(a[i].second));
		string rly=itos(ave[i]),pdy=itos(bhat*i+ahat),cc=itos(ave[i]-(bhat*i+ahat));
		cout<<"│";fout(r1,9);
		cout<<"│";fout(r2,9);
		cout<<"│";fout(r3,9);
		cout<<"│";fout(rly,9);
		cout<<"│";fout(pdy,9);
		cout<<"│";fout(cc,8);
		cout<<"│\n";
		if(i!=n){
			cout<<"├————————————————————————————————————————————————————————————————————│\n";
		}else{
			cout<<"└————————————————————————————————————————————————————————————————————┘\n";
		}
	}
}
原文