欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

codeforces 712A. Memory and Crow

程序员文章站 2022-04-20 09:51:42
2019-05-18 08:48:27 加油,加油,坚持!!! 这道题我没有想出公式推导,只是按照模拟题来做,第5个样例超时 样例超时,方法错误 https://www.cnblogs.com/ECJTUACM-873284962/p/6375011.html AC代码: 我的代码: ......

2019-05-18

08:48:27

加油,加油,坚持!!!

这道题我没有想出公式推导,只是按照模拟题来做,第5个样例超时

样例超时,方法错误

https://www.cnblogs.com/ecjtuacm-873284962/p/6375011.html

ac代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_n = 1e5 + 5;
ll a[max_n];
ll b[max_n];

int main()
{
    ll n;
    ll i, j;
    scanf("%lld", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(i = 0; i < n - 1; i++)
    {
        b[i] = a[i] + a[i + 1];
        cout << b[i] << " ";
    }
    b[n - 1] = a[n - 1];
    cout << b[n - 1] ;
    return 0;
}

我的代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_n = 1e5 + 5;
ll a[max_n];
ll b[max_n];

int main()
{
    ll n;
    ll i, j;

    scanf("%lld", &n);
    for (i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    b[n] = a[n];
    //超时
    for (i = n - 1; i >= 1; i--)
    {
        ll count = 0;
        ll m = 1;
        for (j = i + 1; j <= n; j++)
        {            
            count = count + (m * b[j]);
            m = m * -1;
        }
        b[i] = a[i] + count;
        
    }
    for (i = 1; i <= n; i++)
    {
        if (i == n)
        {
            cout << b[i];
        }
        else
        {
            cout << b[i] << " ";
        }
    }

    return 0;
}