UVa 10014 - Simple calculations

本文介绍了解决UVa10014-Simple calculations问题的方法,通过数学推导简化了求解过程,并提供了一段C++代码实现,该程序能够快速计算出给定序列的特定公式结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门UVa 10014 - Simple calculations

数列题.

推倒的过程就不详细说了, 第一步先推到

然后我就卡在这里了.

其实这里还可以往下推.

取n = 1, 2, 3.....n相加, 最后得到

OK.


#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
    int T, n, cnt = 1;
    double a, b;
    register double sum, tempSum, temp;     //这里用register比普通的double快0.012s
    register int i;
    scanf("%d", &T);
    while (T--)
    {
        if (cnt > 1)
            printf("\n");
        cnt++;
        sum = tempSum = 0;
        scanf("%d%lf%lf", &n, &a, &b);
        for (i = 0; i < n; i++)
        {
            scanf("%lf", &temp);
            tempSum += temp;
            sum += tempSum;
        }
        printf("%.2f\n", (n * a - 2 * sum + b) / (n + 1));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值