Simple calculations(数学都不会了)
来源:互联网 发布:软件样本捕获 编辑:程序博客网 时间:2024/04/28 00:45
Description
There is a sequence of n+2 elements a0, a1, ..., an+1 (n <= 3000, -1000 <= ai <=1000). It is known that ai = (ai-1 + ai+1)/2 - ci for each i=1, 2, ..., n.
You are given a0, an+1, c1, ... , cn. Write a program which calculates a1.
Input
The first line of an input contains an integer n. The next two lines consist of numbers a0 and an+1 each having two digits after decimal point, and the next n lines contain numbers ci (also with two digits after decimal point), one number per line.
The first line of an input contains an integer n. The next two lines consist of numbers a0 and an+1 each having two digits after decimal point, and the next n lines contain numbers ci (also with two digits after decimal point), one number per line.
Output
The output file should contain a1 in the same format as a0 and an+1.
The output file should contain a1 in the same format as a0 and an+1.
Sample Input
1
50.50
25.50
10.15
1
50.50
25.50
10.15
Sample Output
27.85
27.85
我又不会了,天呀,我弱爆了,高中的还是初中的数列都不会了!!强烈鄙视自己!参考别人推导,现推导如下!!
csdn renyuzhuo0
由原式得:
2a[i]=a[i-1]+a[i+1]-c[i]
所以
2a[i] =a[i-1]+a[i+1]-c[i]
2a[i-1]=a[i-2]+a[i]-c[i-1]
2a[i-2]=a[i-3]+a[i-1]-c[i-2]
:
2a[2]=a[1]+a[3]-c[2]
2a[1]=a[0]+a[2]-c[1]
左右两侧分别相加得:
a[i]+a[1]=a[0]+a[i+1]-(c[1]+c[2]+...+c[i-2]+c[i-1]+c[i])
即:c[1]+c[2]+...+c[i-2]+c[i-1]+c[i]=a[0]+a[i+1]-a[i]-a[1]
所以
a[0]+a[i+1]-a[i]-a[1]=c[1]+c[2]+...+c[i-2]+c[i-1]+c[i]
a[0]+a[i]-a[i-1]-a[1]=c[1]+c[2]+...+c[i-2]+c[i-1]
a[0]+a[i-1]-a[i-2]-a[1]=c[1]+c[2]+c+c[i-2]
:
a[0]+a[3]-a[2]-a[1]=c[1]+c[2]
a[0]+a[2]-a[1]-a[1]=c[1]
左边右边分别相加:
化简得:
n*a[0]+a[i+1]-(n+1)*a[1]=n*c[1]+(n-1)*c[2]+...c[n]
a[1]=(n*a[0]+a[i+1]-(n*c[1]+(n-1)*c[2]+...c[n]))/(n+1)
此时可看出,除了a[1],其他都已知,可编代码:
#include<stdio.h>#include<string.h>int main(){ int n, i; double first, final, sum, temp, ans; while(scanf("%d",&n)!=EOF) { scanf("%lf", &first); scanf("%lf", &final); for(i=1,sum=0; i<=n; ++i) { scanf("%lf", &temp); sum += 2.0*(n+1-i)*temp; //c数组求和 } ans = n*first+final-sum; printf("%.2lf\n", ans/(n+1)); } return 0;}
- Simple calculations(数学都不会了)
- UVa 10014 Simple calculations (数学)
- uva 10014 Simple calculations(数学推导)
- uva Simple calculations (数学推导)
- UVA Simple calculations (数学推导)
- Simple calculations
- Simple calculations
- Simple calculations
- Simple calculations
- Simple calculations
- UVA 10014(暑假-数学(3) -F - Simple calculations)
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
- UVa 10014 - Simple calculations
- ural 1047 Simple Calculations
- uva 10014 - Simple calculations
- poj 2601 Simple calculations
- uva 10014 Simple calculations
- UvaOJ 10014 - Simple calculations
- HDU 3333 树状数组+离线处理
- IE10 可输入下拉框
- php漏洞php后门防范(从配置文件上)
- tableView点击更多及搜索栏
- 这是oracle包实体里面的一个存储过程 oracle存储过程中的if...elseif...else用法
- Simple calculations(数学都不会了)
- YUV420SP
- 【xtku】教你巧用库完成照片搜索
- Median of Two Sorted Arrays
- ubuntu下android设备连接出现error: insufficient permissions for device 错误
- 树结构数据查询
- 安卓开发自定义弹出框的简单方式(纯代码布局)
- 如何设置Matlab输出到Word中图片的大小
- android监听键盘事件KeyEvent