A1 = ?

A1 = ?

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8204    Accepted Submission(s): 5071


Problem Description
有如下方程:A i = (A i-1 + A i+1)/2 - C i (i = 1, 2, 3, .... n).
若给出A 0, A n+1, 和 C 1, C 2, .....C n.
请编程计算A 1 = ?
 

Input
输入包括多个测试实例。
对于每个实例,首先是一个正整数n,(n <= 3000); 然后是2个数a 0, a n+1.接下来的n行每行有一个数c i(i = 1, ....n);输入以文件结束符结束。
 

Output
对于每个测试实例,用一行输出所求得的a1(保留2位小数).
 

Sample Input
  
1 50.00 25.00 10.00 2 50.00 25.00 10.00 20.00
 

Sample Output
  
27.50 15.00
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2082  2094  2076  2079  2093 
//因为:Ai=(Ai-1+Ai+1)/2 - Ci,
//      A1=(A0  +A2  )/2 - C1;
//      A2=(A1  +  A3)/2 - C2 , ...
//=>    A1+A2 = (A0+A2+A1+A3)/2 - (C1+C2)
//      2[(A1+A2)+(C1+C2)] = A0+A2+A1+A3;
//      A1+A2 = A0+A3 - 2(C1+C2);
//=>    A1+A2 =  A0+A3 - 2(C1+C2)
//同理可得:
//      A1+A1 =  A0+A2 - 2(C1)
//      A1+A2 =  A0+A3 - 2(C1+C2)
//      A1+A3 =  A0+A4 - 2(C1+C2+C3)
//      A1+A4 =  A0+A5 - 2(C1+C2+C3+C4)
//      ...
//      A1+An = A0+An+1 - 2(C1+C2+...+Cn)
//----------------------------------------------------- 左右求和
//     (n+1)A1+(A2+A3+...+An) = nA0 +(A2+A3+...+An) + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn)
//
//=>   (n+1)A1 = nA0 + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn)
//
//=>   A1 = [nA0 + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn)]/(n+1)

#include <iostream>
#include <cstdio>

using namespace std;
int main ()
{
    int i,j,n;
    double sum;
    while (~scanf("%d",&n))
    {
        sum=0;
        double a[3500],c[3500],d;
        scanf("%lf%lf",&a[0],&a[n+1]);
        for (i=1; i<=n; i++)
            scanf("%lf",&c[i]);
        a[1]=n*a[0]+a[n+1];
        for (i = n, j = 1; i >=1&&j <= n; j++,i--)
            sum += i*c[j];
        a[1] = (a[1] - 2*sum)/(n+1);
        //sum+=c[i];
        //cout<<a[1]<<endl;
        printf ("%.2lf\n",a[1]);
    }
    return 0;
}

2025-07-18 09:08:33.930 [TID: N/A] [http-nio-8000-exec-2] DEBUG o.s.j.s.SQLErrorCodeSQLExceptionTranslator -Translating SQLException with SQL state '42601', error code '0', message [ERROR: syntax error at or near "AND" 位置:1302] for task [ ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ### The error may exist in file [E:\LG\api\so\target\classes\mybatis\Sosoqq1Repository.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select confmWt,totalOnOrderWt, (confmWt-totalOnOrderWt) as "notEntrusted" from ( AND (A1.ORDER_MONTH >= ?) AND (A1.ORDER_MONTH <= ?) and (A1.COMPANY_CODE = ?) and (A1.ORDER_TYPE_CODE = ?) and (A1.SALE_ORG_CODE = ?) and (A1.SALE_DEPT_CODE = ?) ) ### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ] 2025-07-18 09:08:33.958 [TID: N/A] [http-nio-8000-exec-2] DEBUG o.s.web.servlet.DispatcherServlet -Failed to complete request: org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ### The error may exist in file [E:\LG\api\so\target\classes\mybatis\Sosoqq1Repository.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select confmWt,totalOnOrderWt, (confmWt-totalOnOrderWt) as "notEntrusted" from ( AND (A1.ORDER_MONTH >= ?) AND (A1.ORDER_MONTH <= ?) and (A1.COMPANY_CODE = ?) and (A1.ORDER_TYPE_CODE = ?) and (A1.SALE_ORG_CODE = ?) and (A1.SALE_DEPT_CODE = ?) ) ### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 execute XApplicationEvent ...class org.springframework.web.context.support.ServletRequestHandledEvent 2025-07-18 09:08:33.973 [TID: N/A] [http-nio-8000-exec-2] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] -Servlet.service() for servlet [dispatcherServlet] in context with path [/api/so] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ### The error may exist in file [E:\LG\api\so\target\classes\mybatis\Sosoqq1Repository.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select confmWt,totalOnOrderWt, (confmWt-totalOnOrderWt) as "notEntrusted" from ( AND (A1.ORDER_MONTH >= ?) AND (A1.ORDER_MONTH <= ?) and (A1.COMPANY_CODE = ?) and (A1.ORDER_TYPE_CODE = ?) and (A1.SALE_ORG_CODE = ?) and (A1.SALE_DEPT_CODE = ?) ) ### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302 ; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302] with root cause org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND" 位置:1302
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值