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

题目来源

German Collegiate Programming Contest 2018​

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
typedef long long ll;
#define lowbit(x) (x&(-x))
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
using namespace std;
#define pi acos(-1)
int n;
const int N=1e6+;
const ll inf=1e14+;
ll a[N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
}
ll l=,r=;
ll maxx=inf,minn=;//一定要>=0
for(int i=;i<=n;i++){
if(i%==){
l=a[i]-r;
maxx=min(maxx,l);
}
if(i%==){
r=a[i]-l;
minn=max(minn,r*(-));
}
}
//解的范围[minn,maxx]
/*
如 12 5 7 11
x 12-x -7+x 14-x x-3
令x==0 0 12 -7 14 -3
[7,12]
*/ if(minn>maxx){
printf("0\n");
}
else{
printf("%lld\n",maxx-minn+);
}
return ;
}

Down the Pyramid的更多相关文章

  1. CF 676B Pyramid of Glasses[模拟]

    B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Spatial pyramid pooling (SPP)-net (空间金字塔池化)笔记(转)

    在学习r-cnn系列时,一直看到SPP-net的身影,许多有疑问的地方在这篇论文里找到了答案. 论文:Spatial Pyramid Pooling in Deep Convolutional Net ...

  3. 论文笔记之:Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks

    Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks NIPS 2015  摘要:本文提出一种 ...

  4. codeforces 676B B. Pyramid of Glasses(模拟)

    题目链接: B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. hdu 5432 Pyramid Split 二分

    Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...

  6. Spatial Pyramid Matching 小结

    Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...

  7. pyramid的第一个项目

    1,安装pyramid --在次之前最好先安装python virtualenv --python virtualenv ---激活方式pyenv activate pip install pyram ...

  8. OpenGL蓝宝书第五章代码勘误以及惯性坐标系去解释模型变换:Pyramid.cpp

    假设你也发现依照教程代码完毕贴图时,你会底面的坐标和寻常顶点坐标正负相反,比方-1.0f, -1.0f, -1.0f这个顶点相应的却是世界坐标中1.0f,-1.0f,1.0f 问题到底出如今哪里? 原 ...

  9. Golden Pyramid

    Golden Pyramid Our Robo-Trio need to train for future journeys and treasure hunts. Stephan has built ...

  10. hdu 5432 Pyramid Split(二分搜索)

    Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...

随机推荐

  1. NIO学习之Channel

    一.Channel基础 通道是一个对象,通过它可以读取和写入数据,Channel就是通向什么的道路,为数据的流向提供渠道: 在传统IO中,我们要读取一个文件中的内容使用Inputstream,该str ...

  2. JavaScript判断图片是否已经加载完毕的方法汇总

    在网上有很多关于判断图片是否已经加载完毕的文章,但是有的浏览器并不适合,下面小编给大家分享一些有关JavaScript判断图片是否已经加载完毕方法汇总,具体内容如下所示: 一.onload事件 通过监 ...

  3. 转:IOS程序之间的文件共享

    原文 System-Declared Uniform Type Identifiers One of the common tasks that an iOS developer has to do ...

  4. bootstrap fileinput 上传文件

    最近用到文件上传功能, 说实话:以前遇到过一次,COPY了别人的代码 结束! 这次又要用,可是看到别人很酷的文件上传功能,心痒了! 好吧.简单的办法,找控件: bootstrap fileinput ...

  5. C# 初始学习心情

    当听说需要转做.net的时候.内心是忐忑不安的.因为突然从前端转向后端,几乎完全颠倒了...一个注重界面实现功能.一个注重逻辑的开发,然并卵,服从需求吧. 虽说公司需要你转.但是时间是不允许的,所以只 ...

  6. C#字段声明部分如何调用该类中的方法进行初始化?

    问题描述: 有时,功能需求,需要在初始化字段时,需要视不同情况赋予不同字段值. 解决办法: 将方法设为static即可. e.g. public string str = SetStr(); publ ...

  7. MySQL表的碎片整理和空间回收小结

    MySQL表碎片化(Table Fragmentation)的原因 关于MySQL中表碎片化(Table Fragmentation)产生的原因,简单总结一下,MySQL Engine不同,碎片化的原 ...

  8. 数据库limit子句

    limit子句:用来限定语句执行结果的偏移量,有一个或者两个参数:第一个参数表示返回结果首行偏移量,第二个参数表示最大返回行数.例如:SELECT * FROM employees ORDER BY ...

  9. Python3获取大量电影信息:调用API

    实验室这段时间要采集电影的信息,给出了一个很大的数据集,数据集包含了4000多个电影名,需要我写一个爬虫来爬取电影名对应的电影信息. 其实在实际运作中,根本就不需要爬虫,只需要一点简单的Python基 ...

  10. 如何处理错误消息Please install the Linux kernel header files

    Please install the Linux kernel "header" files matching the current kernel 当我启动minilkube时遇 ...