• Codeforces Round #370 (Div. 2) A. Memory and Crow 水题


    A. Memory and Crow

    题目连接:

    http://codeforces.com/contest/712/problem/A

    Description

    There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:

    The crow sets ai initially 0.
    The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... 
    

    Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

    Input

    The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.

    The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

    Output

    Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

    Sample Input

    5
    6 -4 8 -2 3

    Sample Output

    2 4 6 1 3

    Hint

    题意

    题解:

    显然知道an=bn,然后剩下的可以手动推一下公式,就可以递推出来了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5+7;
    int a[maxn],n;
    long long b[maxn];
    int main()
    {
        scanf("%d",&n);
        long long sum = 0;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=n;i>=1;i--)
        {
            sum*=-1;
            b[i]=a[i]-sum;
            sum+=b[i];
        }
        for(int i=1;i<=n;i++)
            printf("%lld ",b[i]);
        printf("
    ");
    }
  • 相关阅读:
    进程、线程、线程安全理解
    查日志常用Linux命令
    Spring容器管理Bean的生命周期
    在Linux模拟浏览器访问下载文件
    在windows上安装mysql
    java判断ip和端口是否通信正常
    Mongodb开启慢查询
    golang 中奇怪的空切片
    关于 MySQL sql_log_bin
    MySQL read_only 与 super_read_only 之间的关系
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5867759.html
Copyright © 2020-2023  润新知