Squared Error 数学

Squared Error 数学

链接

题解
以a,b,c为例
(b-a)(b-a)+(c-a)(c-a)+(c-b)(c-b)=a✖a+b✖b+c✖c -(a+b+c)✖(a+b+c)

代码

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<string.h>
#include<time.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cctype>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define ld long double
inline int read()
{
    char ch = getchar();int x = 0, f = 1;
    while(ch<'0'||ch>'9'){if(ch == '-') f = -1;ch = getchar();}
    while('0'<=ch && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
    return x*f;
}
ll mod=1e9+7;
ll INF=1e15;
ll Inf=0x3f3f3f3f;

const int N=3e5+5;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     
    int a;
    ll sum=0;
    ll ans=0;
    ll n;
    cin>>n;
    for(ll i=0;i<n;++i)
    {
        a=read();
        ans+=n*a*a;
        sum+=a;
    }    
    ans-=sum*sum;
    cout<<ans<<endl;
 
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值