Down the Pyramid

Do you like number pyramids? Given a number sequence that represents the base, you are usually supposed to build the rest of the "pyramid" bottom-up: For each pair of adjacent numbers, you would compute their sum and write it down above them. For example, given the base sequence [1, 2, 3][1,2,3], the sequence directly above it would be [3, 5][3,5], and the top of the pyramid would be [8][8]:

However, I am not interested in completing the pyramid – instead, I would much rather go underground. Thus, for a sequence of nn non-negative integers, I will write down a sequence of n + 1n+1 non-negative integers below it such that each number in the original sequence is the sum of the two numbers I put below it. However, there may be several possible sequences or perhaps even none at all satisfying this condition. So, could you please tell me how many sequences there are for me to choose from?

Input Format

The input consists of:

  • one line with the integer nn (1 \le n \le 10^6)(1≤n≤106), the length of the base sequence.
  • one line with n integers a_1, \cdots , a_na1​,⋯,an​ (0 \le ai \le 10^8(0≤ai≤108 for each i)i), forming the base sequence.

Output Format

Output a single integer, the number of non-negative integer sequences that would have the input sequence as the next level in a number pyramid.

样例输入1

6
12 5 7 7 8 4

样例输出1

2

样例输入2

3
10 1000 100

样例输出2

0

 

#include <iostream>
using namespace std;
const int inf=1e6+10;
int arr[inf];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d",&arr[i]);
        int minl=1e8+10;
        int minr=1e8+10;   
        int temp=0;
        minl=temp;
        for(int i=0;i<n;i++)                     
        {
            if(i%2==0)
            {
                temp=arr[i]-temp;
                if(temp<minr)
                    minr=temp;    
            }
            else
            {
                temp=arr[i]-temp;
                if(temp<minl)
                    minl=temp;
            }
        }
        if(minr>0)               
        {
            int flag=minr+1;
            if( flag+minl>0 )         //零也是一个特殊的,使用零可以,使用其他的应该也可以。 
                printf("%d\n",flag+minl);
            else
                printf("0\n");
        } 
        else if(minl==0&&minr==0) 
        {
            printf("1\n");
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值