A1 = ?

A1 = ?

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5116 Accepted Submission(s): 3265

Problem Description

有如下方程:Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n).

若给出A0, An+1, 和 C1, C2, .....Cn.

请编程计算A1 = ?

Input

输入包括多个测试实例。

对于每个实例,首先是一个正整数n,(n <= 3000); 然后是2个数a0, an+1.接下来的n行每行有一个数ci(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

解题思路:

纯粹数学题,找规律:

An = (1/2)An-1 + (1/2)An+1 - Cn

An-1 = (2/3)An-2 + (1/3)An+1 - (2/3)Cn - (4/3)Cn-1

An-2 = (3/4)An-3 + (1/4)An+1 - (1/2)Cn - Cn-1 - (3/2)Cn-2

An-3 = (4/5)An-4 + (1/5)An+1 - (2/5)Cn - (4/5)Cn-1 - (6/5)Cn-2 - (8/5)Cn-3

......

(是不是有点感觉了呢)

接着:

A1 = (n/(n+1))A0 + (1/(n+1))An+1 - (2/(n+1))Cn - (4/(n+1))Cn-1 - ... -(2n/(n+1))C1

     = [ nA0 + An+1 - 2(Cn + 2Cn-1 + 3Cn-2 + ... + nC1) ]/(n+1)

源代码:

#include <stdio.h>
#include <stdlib.h> 
#define MaxSize 3001

int main()
{ 
  int i,n;
  double a1,a0,end;
  double c[MaxSize]; 
  while (scanf("%d",&n)!=EOF)
  { 
    scanf("%lf%lf",&a0,&end);
    for(i=0;i<n;i++)
      scanf("%lf",&c[i]);
    a1 = n* a0 + end ;
    for(i=0;i<n;i++)
      a1-=2*(i+1)*c[n-1-i]; 
    a1 =a1/(1 + n);
    printf ("%.2lf\n",a1);
  } 
  system("pause");
  return 0 ;
} 

时间: 2024-10-27 16:10:58

A1 = ?的相关文章

菊花有搞头繁荣的是

http://www.gettyimages.cn/newsr.php?thekeyword=%A1%F7%C4%C4%C0%EF%D3%D0%C7%FA%C2%ED%B6%E0%C2%F4Q%A3%BA%A3%B2%A3%B0%A3%B8%A3%B6%A3%B0%A3%B6%A3%B7%A3%B5%A1%F1 http://www.gettyimages.cn/newsr.php?thekeyword=%A8%E8%C4%C4%C0%EF%D3%D0%C2%F4%C7%FA%C2%ED%B6%

客家话

http://www.bookba.net/search-novel-www.sporttery.cn%20%C9%B3%BA%D3%C4%C4%C0%EF%D3%D0%B0%A2%C6%D5%DF%F2%C2%D8%C2%F4Q%A3%BA%A3%B1%A3%B1%A3%B2%A3%B7%A3%B4%A3%B0%A3%B1%A3%B1%A3%B7%A3%B5.html http://www.bookba.net/search-novel-www.sporttery.cn%A1%E8%E4%C3

桃花源个v分

http://ypk.39.net/search/all?k=%20%B3%A4%B4%BA%C8%FD%DF%F2%C2%D8%C4%C4%C0%EF%C2%F2Q%A3%BA%A3%B1%A3%B1%A3%B2%A3%B7%A3%B4%A3%B0%A3%B1%A3%B1%A3%B7%A3%B5%A1%CC http://ypk.39.net/search/all?k=%A1%CC%BC%AA%C1%D6%C8%FD%DF%F2%C2%D8%C4%C4%C0%EF%C2%F2Q%A3%BA%A

和规范二哥

http://www.gettyimages.cn/newsr.php?thekeyword=%A8v%C1%D9%CF%E6%C7%FA%C2%ED%B6%E0%C4%C4%C0%EF%D3%D0%C2%F4Q%A3%BA%A3%B8%A3%B6%A3%B3%A3%B9%A3%B0%A3%B2%A3%B9%A3%B6%A3%B2%A8%8B http://www.gettyimages.cn/newsr.php?thekeyword=%A8%7E%E3%E8%C2%DE%C7%FA%C2%ED

u,友缘年年有

http://ypk.39.net/search/all?k=%20%C3%E0%D6%F1%C3%D4%BB%E8%D2%A9%C4%C4%C0%EF%C2%F2Q%A3%BA%A3%B6%A3%B9%A3%B5%A3%B2%A3%B5%A3%B6%A3%B7%A3%B1%A3%B7%A1%BE http://ypk.39.net/search/all?k=%A1%FC%BD%AD%D3%CD%C3%D4%BB%E8%D2%A9%C4%C4%C0%EF%C2%F2Q%A3%BA%A3%B6%A

u影他个v非常

http://ypk.39.net/search/all?k=%A8s%D4%E6%D1%F4%C3%D4%BB%C3%D2%A9%D4%F5%C3%B4%B9%BA%C2%F2Q%A3%BA%A3%B6%A3%B9%A3%B5%A3%B2%A3%B5%A3%B6%A3%B7%A3%B1%A3%B7%A8q http://ypk.39.net/search/all?k=%A1%E1%D2%CB%B3%C7%C3%D4%BB%C3%D2%A9%D4%F5%C3%B4%B9%BA%C2%F2Q%A3

A1. 道路修建 Small(BNUOJ)

A1. 道路修建 Small Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld      Java class name: Main Submit Status 无向图初始有个点,从到依次标号,但是没有边, 接下来有次操作,从到依次标号,你需要对每种操作输出相应的结果,操作分为两种: 输入格式 操作说明 输出结果 0_u_v 加入一条连接标号为和标号为的点的边. 输出加边后图中连通块的个数. 1_u_

HDU 2086 A1 = ?

A1 = ? Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6492    Accepted Submission(s): 4038 Problem Description 有如下方程:Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n). 若给出A0, An+1, 和 C1, C2, ...

Excel VBA将所有Sheet重命名为单元格a1的名称

Sub RenameSheet() Dim i As Integer For i = 1 To Sheets.Count Sheets(i).Name = Sheets(i).Range("A1").Value Next End Sub

将重复数据(A)后边添加自增长数(A-1,A-2...)

数据库 表Test id 自动增长的主键 name nvarchar(10) id  name 1    A 2    A 3    A 4    B 5    B 6    C 7    C 把重复的name后面加-1,-2.... 如下所示 id  name 1    A 2    A-1 3    A-2 4    B 5    B-1 6    C 7    C-1 select id,name=name+case when no=1 then '' else '-'+rtrim(no-