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 ...
随机推荐
- 1121 - Reverse the lights 思维题
http://www.ifrog.cc/acm/problem/1121 我看到这些翻转的题就怕,可能要练下这些专题. 我最怕这类题了. 一开始想了下dp, dp[i][0 / 1]表示完成了前i位, ...
- spring boot Filter过滤器的简单使用
springboot使用Filter过滤器有两种方式: 一种是实现Filter接口然后通过@Component注解向项目加入过滤器 另一种是通过配置类来配置过滤器 @Component public ...
- Spring Cloud--Feign服务调用组件的使用实例
引入依赖: 启动类上添加@EnableFeignClients注解: 写调用接口: 直接@Autowired注入服务调用接口: 底层使用了动态代理,对接口进行了实现. 并且封装了RestTemplat ...
- linux下指定特定用户执行命令
虽然很简单但是百度找的大部分不能用,我是没找到,后来从google找到的 sudo -H -u www bash -c 'nohup /home/web/ke/upfileserver /home/w ...
- 微信开发 config:invalid url domain
当遇到config:invalid url domain 有2种可能 1.没有配置url. 2.url配置错误.配置url如http://write.blog.csdn.NET/,就要这样配置writ ...
- 在使用seek()函数时,有时候会报错为 “io.UnsupportedOperation: can't do nonzero cur-relative seeks”,代码如下:
__author__ = 'ZHHT' #!/usr/bin/env python # -*- coding:utf-8 -*- import os f = open("test1" ...
- 洛谷 P2002 消息扩散
题目背景 本场比赛第一题,给个简单的吧,这 100 分先拿着. 题目描述 有n个城市,中间有单向道路连接,消息会沿着道路扩散,现在给出n个城市及其之间的道路,问至少需要在几个城市发布消息才能让这所有n ...
- windows系统下使用.net简单操作redis
首先.net需要引入如下几个文件,在gitub或者官网应该是有的: 然后配置一下redis服务器: 端口: IP: 然后先启动 redis-server.exe: 出现如下效果表示成功 再启动:re ...
- [Tracking] KCF + KalmanFilter目标跟踪
基于KCF和MobileNet V2以及KalmanFilter的摄像头监测系统 简介 这是一次作业.Tracking这一块落后Detection很多年了,一般认为Detection做好了,那么只要能 ...
- 用户输入和while循环
函数input()的工作原理 message=input('Tell me something,and I will repeat it back to you:') print(message) 编 ...