URAL 1047 Simple Calculations
生活随笔
收集整理的這篇文章主要介紹了
URAL 1047 Simple Calculations
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
URAL_1047
??? 根據原式可以得a[n+1]-a[n]=a[n]-a[n-1]+2*c[n]①,設S[n]=c[1]+c[2]+…+c[n],對①式疊加相消可以得到a[n+1]-a[1]=a[n]-a[0]+2*S[n],整理一下得到a[n+1]-a[n]=a[1]-a[0]+2*S[n]②,對②式疊加相消可以得到a[n+1]-a[1]=n*(a[1]-a[0])+2*(S[1]+S[2]+…+S[n]),這樣就可以求得a[1]了。
#include<stdio.h> #include<string.h> int N; void solve() {int i;double x, y, s = 0, a = 0, c;scanf("%lf%lf", &x, &y);for(i = 0; i < N; i ++){scanf("%lf", &c);a += c;s += a;}printf("%.2f\n", -(2 * s - N * x - y) / (N + 1)); } int main() {while(scanf("%d", &N) == 1){solve();}return 0; }轉載于:https://www.cnblogs.com/staginner/archive/2012/05/07/2487170.html
總結
以上是生活随笔為你收集整理的URAL 1047 Simple Calculations的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 摩托车过长时间不使用离合器粘连怎么办?
- 下一篇: 区分一下强制类型转换运算符重载/赋值运算