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], the sequence directly above it would be [3, 5], and the top of the pyramid would be [8]:

  However, I am not interested in completing the pyramid – instead, I would much rather go underground. Thus, for a sequence of n non-negative integers, I will write down a sequence of n + 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

The input consists of:

• one line with the integer n (1 ≤ n ≤ 106 ), the length of the base sequence.

• one line with n integers a1, . . . , an (0 ≤ ai ≤ 108 for each i), forming the base sequence.

Output

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.

Sample Input 1           Sample Output 1

6                2

12 5 7 7 8 4

Sample Input 2           Sample Output 2

3               0

10 1000 100

概述:给你一个序列,根据这个序列,写出它下一层金字塔的可能出现的序列数目。

分析: 假设给出n=4的序列b1,b2,b3,b4.你要求的就是它下方的一层a1,a2,a3,a4,a5.

    明显有

      b1=a1+a2,b2=a2+a3,b3=a3+a4,b4=a4+a5;

    从而得到

      a1=a1,

      a2=b1-a1,

      a3=b2-a2=b2-b1+a1,

      a4=b3-a3=b3-b2+b1-a1,

      a5=b4-a4=b4-b3+b2-b1+a1;

    这时可以发现a序列的确定仅与a1相关,换句话说求a序列的数目也就是求a1的数目。问题转换成了求解求a1的范围使得a1~a5都≥0。

话不多说,上代码  

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 const int INF = 0x3f3f3f3f;
 5 const int maxn = 1000000 + 5;
 6 int b[maxn];
 7 int main()
 8 {
 9     int n;
10     cin >> n;
11     for (int i = 1; i <= n;i++)
12         cin >> b[i];
13     int mina1 = 0, maxa1 = INF;
14     int temp = 0;
15     for (int i = 1; i <= n;i++)
16     {
17         temp = b[i] - temp;
18         if(i%2)
19             maxa1 = min(maxa1, temp);
20         else
21             mina1 = max(mina1, -temp);
22     }
23     cout << mina1 << " " << maxa1 << endl;
24     if(maxa1>=mina1)
25         cout << maxa1 - mina1 + 1;
26     else
27         cout << 0;
28     return 0;
29 }

View Code

  

转载于:https://www.cnblogs.com/chen-tian-yuan/p/10601761.html

GCPC 2018 – Problem D: Down the Pyramid相关推荐

  1. Codeforces 补题记录

    首先总结一下前段时间遇到过的一些有意思的题. Round #474 (Div. 1 + Div. 2, combined)   Problem G 其实关键就是n这个数在排列中的位置. 这样对于一个排 ...

  2. HDU 1573 X问题 [中国剩余定理]

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  3. 人脸方向学习(十七):Face Detection-论文整理-解读

    整理的人脸系列学习经验:包括人脸检测.人脸关键点检测.人脸优选.人脸对齐.人脸特征提取等过程总结,有需要的可以参考,仅供学习,请勿盗用.https://blog.csdn.net/TheDayIn_C ...

  4. 达摩院高清人像美肤模型ABPN CVPR论文深入解读

    一.论文&代码 论文:ABPN: Adaptive Blend Pyramid Network for Real-Time Local Retouching of Ultra High-Res ...

  5. codeup墓地目录(算法笔记习题刷题笔记)

    在线codeup contest 地址:http://codeup.cn/contest.php Contest100000575 - <算法笔记>3.1小节--入门模拟->简单模拟 ...

  6. 【论文翻译】-- GaitSet: Regarding Gait as a Set for Cross-View Gait Recognition

    本文是复旦大学发表于 AAAI 2019 的工作.截至目前CASIA-B正确率最高的网络. 英文粘贴原文,google参与翻译但人工为主.有不对的地方欢迎评论. 粉色部分为本人理解添加,非原文内容. ...

  7. (1)课程简介-CS231A:Computer Vision, From 3D Reconstruction to Recognition

    斯坦福大学-源地址: CS231A: Computer Vision, From 3D Reconstruction to Recognition CS231AGitHub笔记:https://git ...

  8. openCV的sobel算子的深度学习卷积网络部分的C语言源码

    参考的三种边缘检测算子其一,未完待续..灰度或结构等信息的突变位置是图像的边缘,图像的边缘有幅度和方向属性,沿边缘方向像素变化缓慢,垂直边缘方向像素变化剧烈.因此,边缘上的变化能通过梯度计算出来. 同 ...

  9. 【原创·论文翻译】GaitSet-旨在用自己的语言表达出作者的真实意图

    GaitSet: Regarding Gait as a Set for Cross-View Gait Recognition 作者:Hanqing Chao1,Yiwei He, Junping ...

  10. 视频插帧(Video Frame interpolation)论文及源码

    视频插帧论文列表(含Code) 蓝色突出表示热门方法 CCF A AAAI 2019 CyclicGen:Deep Video Frame Interpolation Using Cyclic Fra ...

最新文章

  1. CentOS重启启动Apache,VNC
  2. spring MVC、mybatis配置读写分离
  3. 17.1 MySQL主从介绍 17.2 准备工作 17.3 配置主 17.4 配置从 17.5 测试主从同步
  4. jquery easyUI分页dataGrid-Json
  5. 【江苏】2021年下半年软考报考时间及通知
  6. 李飞飞的斯坦福 HAI 招人了,薪资丰厚科研经费管够
  7. java与c语言工作量对比比例,对比平台-- C ++与Java之间的差异
  8. datagridview如何将sqlite实现多表查询_服气!月薪3W的Exceler,居然是这样合并多表数据的...
  9. Solaris 添加删除 用户和组
  10. 英才计划计算机潜质测评试题,员工能力与素质测评题库完整.doc
  11. Windows 8实例教程系列 - 数据绑定高级实例
  12. 用.NET编程风格实现Ajax——Atlas快速入门
  13. Linux操作系统原理
  14. python中导入win32com.client出错问题
  15. Fibonacci Additions (区间加优化)
  16. java 带t日期格式转换_自我整理:java 日期转换
  17. Python 使用 matplotlib 将离散的节点用光滑曲线连接
  18. 重谈联想5G编码投票事件
  19. 圣地亚哥大学计算机科学专业,加州大学圣地亚哥分校计算机科学与工程系
  20. js+HTML实现组织结构图

热门文章

  1. 扩展GridView控件(2) - 复合排序和排序状态提示
  2. python-包机制
  3. 谈Dreamweaver和Webstorm
  4. 动态规划算法 dynamic programming
  5. Linux 如何重启网络
  6. 我的 WinClock 项目系列之一 (概述)
  7. javascript天生就具备类似c#中的委托功能
  8. dcopserver出错解决办法
  9. PHP设计模式——中介者模式
  10. 深入浅出ObjC之消息