2016多校聯合訓練第二場 1001 Acperience 公式推導

        簡單的公式推導題,先把所有的數取絕對值,然後猜測k爲wi的平均數,然後推導分子分母的公式,最後求分子分母的最大公因數後上下同除就好了,代碼如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>//求式子 
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y)  
{  
    if(x%y == 0) return y;  
    else return gcd(y, x%y);  
}  
int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		ll n, up = 0, down, temp = 0;
		scanf("%lld", &n);
		down = n;
		for(int i = 1; i <= n; i++)
		{
			ll t;
			scanf("%lld", &t);
			up += t*t;
			temp += abs(t);
		}
		up = up*n - temp*temp;
		ll gcd1 = gcd(up, down);
		up /= gcd1, down /= gcd1;
		printf("%lld/%lld\n", up, down);
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章