2016多校联合训练第二场 1001 Acperience 公式推导
2016-07-22 17:28
459 查看
简单的公式推导题,先把所有的数取绝对值,然后猜测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;
}
#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;
}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- 【HDU 5366】The mook jong 详解