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. linux批量替换指定文件夹中所有文件的指定内容

    命令:sed -i "s#https#http#g" `grep http -rl VEROMODA` 功能:用来替换当前目录VEROMODA文件夹及子文件夹中所有文件中的http ...

  2. (转)useradd用户,组管理案例

    原文:https://www.cnblogs.com/Csir/p/6403830.html?utm_source=itdadao&utm_medium=referral 示例:要求oldbo ...

  3. Spark Mllib里如何记录开始训练时间、完成训练时间、所需训练时间(图文详解)

    不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第16章 朴素贝叶斯二元分类算法来预测分类StumbleUpon数据集

  4. 洛谷P1965 转圈游戏

    https://www.luogu.org/problem/show?pid=1965 快速幂 #include<iostream> #include<cstdio> #inc ...

  5. springIOC+Mysql+springmvc事务测试题总结

    1.关于http1.1和1.0的长连接和短连接 两个都支持长连接和短连接 http1.0默认为短连接,也就是说,浏览器和服务器每进行一次HTTP操作,就建立一次连接,任务结束就中断连接 http1.1 ...

  6. td 内容自动换行 table表格td设置宽度后文字太多自动换行

    设置table 的 style="table-layout:fixed;" 然后设置td的 style="word-wrap:break-word;" 即可   ...

  7. 不小心踩到的XMAPP的N种问题

    1.在win10上的xampp集成环境中安装mongo扩展 按照网上搜索的下载对应文件后,在phpinfo里面还是找不到mongo的扩展信息,后面也是请教同事帮忙解决: http://www.theg ...

  8. ios 各种锁的使用性能比较

    iOS开发中常用的锁有如下几种 来比较一下遇到加锁的情况: 1. @synchronized 关键字加锁 2. NSLock 对象锁 3. NSCondition  4. NSConditionLoc ...

  9. javascript简单计算器实践

    参考部分资料,编写一个简单的计算器案例,虽然完成了正常需求,但是也有不满之处,待后续实力提升后再来补充,先把不足之处列出: 1:本来打算只要打开页面,计算器的输入框会显示一个默认为0的状态,但是在输入 ...

  10. java控制远程ssh-JSCH(二)

    github: https://github.com/wengyingjian/ssh-java-demo.git 这次找到了一套新的api,叫jsch.网上查了一下,顺便把官网的几个demo给一通拿 ...