uva10014(数学)
2013-05-30 10:58
393 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=955&mosmsg=Submission+received+with+ID+10538028
Simple
calculations
a0, a1,…, an+1(n <=
3000; -1000 <= ai 1000). It is known that
ai= (ai–1 + ai+1)/2 –
cifor each i=1, 2, ..., n. You are given
a0, an+1, c1, ... , cn.
Write a program which calculates a1.
cases, followed by a blank line.
For each test case, the first line of an input file 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.
Each test case will be separated by a single line.
should contain a1 in the same format as a0
and an+1.
Print a blank line between the outputs for two consecutive test
cases.
10014 - Simple calculations
Time limit: 3.000 secondsSimple
calculations
The Problem
There is a sequence of n+2 elementsa0, a1,…, an+1(n <=
3000; -1000 <= ai 1000). It is known that
ai= (ai–1 + ai+1)/2 –
cifor each i=1, 2, ..., n. You are given
a0, an+1, c1, ... , cn.
Write a program which calculates a1.
The Input
The first line is the number of testcases, followed by a blank line.
For each test case, the first line of an input file 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.
Each test case will be separated by a single line.
The Output
For each test case, the output fileshould contain a1 in the same format as a0
and an+1.
Print a blank line between the outputs for two consecutive test
cases.
Sample Input
1 1 50.50 25.50 10.15
Sample Output
27.85 题意:出处http://www.byywee.com/page/M0/S774/774446.html 给出一个数列ci(1<=ci<=n),然后给出数列ai中的a0和a(n+1),并给出一个公式ai = ( a(i-1) + a(i+1) ) / 2 - ci。求a1。 做了很长时候,也没弄对,最后看的别人的解题呈报。。。。。 由给出公式得:2ai = a(i-1) + a(i+1) -2ci ,依次使i=1,2......n,写出n个式子,把它们相加, 获得:a1 + an = a0 + a - 2(c1 + …… + cn), 再使c的下标i=1......n,写出n个式子,把他们相加。 获得:(n + 1)a1 = na0 + an+1 - 2(nc1 + (n-1)c2 + (n-2)c3 + …… + cn)。
自己也推到:a1 + an = a0 + a - 2(c1 + …… + cn), 后面就不会做了。用了种不负责任的态度提交了下。 #include<stdio.h> #include<string.h> #define maxn 3010 double a[maxn],c[maxn]; int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); memset(a,0,sizeof(a)); scanf("%lf%lf",&a[0],&a[n+1]); int i; double sum=0.0; for(i=0;i<n;i++) { scanf("%lf",&c[i]); sum+=(n-i)*c[i]; } printf("%.2lf\n",(a[n+1]+n*a[0]-2*sum)/(n+1)); if(t) printf("\n"); } return 0; }
相关文章推荐
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
- uva 10014 Simple calculations(数学推导)
- UVA 10014 - Simple calculations(数学)
- uva 10014(数学)
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
- UVA 10014 Simple calculations(数学题)
- UVA 10014(暑假-数学(3) -F - Simple calculations)
- UVa 10014 Simple calculations (数学)
- 数学专项number_theory:UVa 10127
- uva 1639 Candy 大数的对数处理 数学期望
- UVa 11538 - Chess Queen (组合数学)
- uva 10325 The Lottery(组合数学-容斥原理)
- UVALive - 3490 Generator 【数学】【高斯消元】
- UVaLIve 2889 | LA 2889 | UVa 12050 - Palindrome Numbers (组合数学)
- uva846简单数学题
- uva10161(数学)
- uva10288(数学期望)
- 【数学】Password, ACM/ICPC Daejon 2010, UVa1262
- uva - UVA 1388 - Graveyard (数学推理)
- POJ1320 UVA138 Street Numbers【Pell方程+数学】