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
题目来源
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的更多相关文章
- CF 676B Pyramid of Glasses[模拟]
B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Spatial pyramid pooling (SPP)-net (空间金字塔池化)笔记(转)
在学习r-cnn系列时,一直看到SPP-net的身影,许多有疑问的地方在这篇论文里找到了答案. 论文:Spatial Pyramid Pooling in Deep Convolutional Net ...
- 论文笔记之:Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks
Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks NIPS 2015 摘要:本文提出一种 ...
- codeforces 676B B. Pyramid of Glasses(模拟)
题目链接: B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input s ...
- hdu 5432 Pyramid Split 二分
Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...
- Spatial Pyramid Matching 小结
Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...
- pyramid的第一个项目
1,安装pyramid --在次之前最好先安装python virtualenv --python virtualenv ---激活方式pyenv activate pip install pyram ...
- OpenGL蓝宝书第五章代码勘误以及惯性坐标系去解释模型变换:Pyramid.cpp
假设你也发现依照教程代码完毕贴图时,你会底面的坐标和寻常顶点坐标正负相反,比方-1.0f, -1.0f, -1.0f这个顶点相应的却是世界坐标中1.0f,-1.0f,1.0f 问题到底出如今哪里? 原 ...
- Golden Pyramid
Golden Pyramid Our Robo-Trio need to train for future journeys and treasure hunts. Stephan has built ...
- 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 ...
随机推荐
- linux批量替换指定文件夹中所有文件的指定内容
命令:sed -i "s#https#http#g" `grep http -rl VEROMODA` 功能:用来替换当前目录VEROMODA文件夹及子文件夹中所有文件中的http ...
- Spark Mllib里如何建立密集向量和稀疏向量(图文详解)
不多说,直接上干货! 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mllib数理统计
- webpack.config.js====output出口文件的配置
output: { filename: './js/[name].[hash:8].js', /* * filename:在使用webpack-dev-server模式时,如果要使用hash,是不可以 ...
- 使用AuthToken架构保护用户帐号验证Cookie的安全性
在项目或者网站开发中,我们很多人很多时候喜欢使用微软的FormsAuthentication类的GetAuthCookie函数生成需要在访客客户端放置的帐号校验Cookie,这个本身没问题,但是很多人 ...
- rest_framework之视图
写一个出版社的增删改查restful接口 models from django.db import models # Create your models here. from django.db i ...
- Ubuntu 11.04 安装 cuda5.0
由于实验需要,于2016年10月15日再Ubuntu11.04安装cuda5.0,但是从网上查找Ubuntu11.04 只有对应的支持的cuda4 版本,cuda 5.0前面版本不支持IDE nisg ...
- win7 dos窗口模拟帧刷新
前几天是白色情人节,临时脑抽写了个表白神器 高端大气上档次,就是不知道该送给谁,经过两天的反射弧思考决定还是写给博客娘吧.- -~ 这个程序就是打开后,在Dos窗口内模拟写出几行字母.其实主要就是模拟 ...
- HTML_3
html列表 有序列表:在网页上定义一个有编号的内容列表可以用<ol>.<li>配合使用来实现,在网页上生成的列表,每条项目上按1.2.3编号,有序列表在实际开发中较少使用.代 ...
- Python 继承、派生、组合、接口、抽象类
继承是一种是的关系,和组合对比,组合是一种有的关系,这两者都是解决代用重用问题的 继承 注意:继承不是遗传,在显示角度中,是通过对象抽象成类,再把这些类抽象成一个,就是父类.是自下而上的过程,在程序中 ...
- idea前后端分离搭建 JavaWeb项目
我们小组在开发的时候, 承诺了前后端分离, 那么就要求前端和后端需要分开搭建. 不能同时放在一个工程项目中. 大致的思路是开启两个Tomcat, 一个跑前端页面, 一个跑后端程序. 1. idea打开 ...