码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 712A. Memory and Crow

时间:2019-05-18 09:54:45      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:const   公式   mem   names   scan   lock   ++   坚持   logs   

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;
}

 

codeforces 712A. Memory and Crow

标签:const   公式   mem   names   scan   lock   ++   坚持   logs   

原文地址:https://www.cnblogs.com/Artimis-fightting/p/10884595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!