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代码

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int b[maxn];
int vis[maxn];
int main()
{int n;scanf("%d",&n);for(int i=2;i<=n;++i){scanf("%d",&b[i]);}for(int i=1;i<=n;++i){a[1]=i;int f=0;for(int j=2;j<=n;++j){int temp=b[j]-a[j-1];if(temp<=n&&temp>=1&&vis[temp]!=i){a[j]=temp;vis[temp]=i;}else{f=1;break;}}if(f) continue;else break;}for(int i=1;i<=n;++i) printf("%d%c",a[i],i==n?'\n':' ');return 0;
}

Photoshoot相关推荐

  1. 2020 GDUT Rating Contest III H. Photoshoot

    H. Photoshoot 链接 题目描述 有n头牛,他们的序号从为1-n,现在他们按一定顺序排好,给出每对相邻的两头牛的序号之和,求出牛现在的序号. 题目分析 因为确定其中一头牛的序号,就可以得出所 ...

  2. Photoshoot(模拟)

    题目描述 Farmer John is lining up his N cows (2≤N≤103), numbered 1-N, for a photoshoot. FJ initially pla ...

  3. Photoshoot(2020jan铜牌)C++

    Photoshoot Farmer John 在给他编号为 1-N的 N头奶牛排队拍照(2≤N≤103).FJ 一开始计划从左向右数第 i 个位置排编号为 ai的奶牛,他在一张纸上写下了排列 a1,a ...

  4. A. Marin and Photoshoot

    A. Marin and Photoshoot 题意: 插入最少的1使得任意长度大于2的连续子串中1的个数不少于0. 题解: 考虑最短不满足条件的字符串可能的形式: 1.00 2. 010 考虑使得每 ...

  5. 2020寒假集训排位赛 Photoshoot 题解(思维,枚举)

    专题链接:https://codeforces.com/group/5yyKg9gx7m/contest/270203/problem/H 思路 枚举a数组第一个数的值,即可推出后面所有的数 注意不要 ...

  6. 24个为Web开发人员准备的CSS3实用教程

    本文搜集了一些关于CSS3的最新教程.你可以根据这些教程或技术来实现网页设计,包括:文字阴影.圆角框.盒模型尺寸计算(box sizing).透明效果处理.多重背景.边框图像等.以下这些都是非常实用的 ...

  7. 39个超实用jQuery实例应用特效

    2019独角兽企业重金招聘Python工程师标准>>> 1.Contextual Slideout:上下文滑动特效 2.Revealing Photo Slider:图片幻灯片特效 ...

  8. 14个jQuery图片放大编辑插件汇总

    基于Web的在线应用已经是一个逐步成熟的趋势,Web应用的丰富多样化,都是基于 JavaScript框架完成的,其中 jQuery 框架被越来越多的Web开发者青睐,它可以让你"少写,多做& ...

  9. USACO 2022 US Open Contest, Bronze

    Problem 1. Photoshoot 迫切希望在郡县集市上赢得最佳奶牛摄影师的 Farmer John 正在尝试为他的 NN 头奶牛拍摄一张完美的照片(2≤N≤2⋅10^5,N 为偶数). Fa ...

最新文章

  1. iOS 直播专题3-前置处理
  2. Ubuntu18.04 JDK8
  3. Python: zip()的使用
  4. 科研SCI论文图片常见问题和错误汇总
  5. java语言中的数据类型_Java语言中关于数据类型的一些总结
  6. 【解题报告】Leecode 438. 找到字符串中所有字母异位词——Leecode每日一题系列
  7. linux更改语言脚本,Linux shell脚本入门——shell语言脚本【CentOS】
  8. wp7设置浏览器主页
  9. c 语言中 %是什么运算符,C 语言基础----详解C中的运算符
  10. c语言10怎么打开文件,Lecture 10 C语言文件操作
  11. python编程入门教程第6讲_Python开发的入门教程(六)-函数
  12. 前段基础html常用标签,web前端开发网络课程,HTML常用的五种标签
  13. JS判断字符串变量是否含有某个字串的实现方法
  14. ps怎么制作流体_PS制作流体字
  15. 拉格朗日插值法总结模板(1~n)
  16. “夜拍王”荣耀10GT上线,不用三脚架也能出夜景大片!
  17. 百度无线音乐盒刷打印服务器,百度无线音乐盒固件
  18. 概览:可视化前端测试
  19. 中国十大无线耳机排行榜,音质好配置高的蓝牙耳机分享
  20. openCV实现图像的空间域增强

热门文章

  1. PHP去除文章的html格式
  2. 脑机接口技术创新与产业发展(2021)报告解读
  3. 关键工具:如何知道自己擅长什么?
  4. c51时钟数码管显示流程图_数码管显示的电子时钟C51程序
  5. 2015的网页设计趋势
  6. 【微信小程序】-- 分包 - 独立分包 分包预下载(四十五)
  7. Jquery (前端)
  8. es6class的继承
  9. 你对燕窝了解多少?2019上海燕窝展带您溯源燕窝
  10. java 鼠标画矩形_用鼠标在画布上绘制Angular2绘制矩形