Photoshoot

农夫约翰正在为他的N头奶牛(2≤N≤103)排队拍照。起初,他计划从左边开始,第i头奶牛编号为ai,并将排列a1,a2,…,aN写在纸上。不幸的是,这张纸被农夫Nhoj偷走了!不过,通过Bessie记录的bi=ai+ai+1(对于1≤i 摘要由CSDN通过智能技术生成

Photoshoot

题目描述
Farmer John is lining up his N cows (2≤N≤103), numbered 1…N, for a photoshoot. FJ initially planned for the i-th cow from the left to be the cow numbered ai, and wrote down the permutation a1,a2,…,aN on a sheet of paper. Unfortunately, that paper was recently stolen by Farmer Nhoj!
Luckily, it might still possible for FJ to recover the permutation that he originally wrote down. Before the sheet was stolen, Bessie recorded the sequence b1,b2,…,bN−1 that satisfies bi=ai+ai+1 for each 1≤i<N.
based on Bessie’s information, help FJ restore the “lexicographically minimum” permutation a that could have produced b. A permutation x is lexicographically smaller than a permutation y if for some j, xi=yi for all i<j and xj<yj (in other words, the two permutations are identical up to a certain point, at which x is smaller than y). It is guaranteed that at least one such a exists.
输入
The first line of input contains a single integer N.
The second line contains N−1 space-separated integers b1,b2,…,bN−1.
输出
A single line with N space-separated integers a1,a2,…,aN.
样例输入

5
4 6 7 6

样例输出

3 1 5 2 4

提示
a produces b because 3+1=4, 1+5=6, 5+2=7, and 2+4=6.

解题思路
暴力枚举第一位数

AC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值