洛谷 https://www.luogu.org/problem/show?pid=T574
来源:互联网 发布:java特种兵 编辑:程序博客网 时间:2024/03/29 06:00
输入格式:
第一行一个正整数N
第二行用空格隔开N个整数Ai
输出格式:
输出N行,第i行表示Ai与A1~A(i-1)中的数的最小差(绝对值),第一行输出-1
set果题
命名:qm==前面,hm==后面,xz==现在
#include<iostream>#include<cstdio>#include<set>#include<cstring>using namespace std;const int inf=99999999;set<int>s;set<int>::iterator it;set<int>::iterator ite;int n,a[200005],cz[200005];int qm=0,hm=0,xz=0,tot=0,sum=0;int main(){ memset(cz,inf,sizeof(cz)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } s.insert(a[1]); cz[1]=-1; for(int i=2;i<=n;i++) { it=s.find(a[i]); if(it!=s.end()) { cz[i]=0; continue; } s.insert(a[i]); it=s.find(a[i]); xz=*it; ite=it; if(it==s.begin()) { ite++; hm=*ite; tot=hm-xz; if(tot<0) tot=-tot; cz[i]=tot; continue; } else if(it!=s.begin()) { ite--; qm=*ite; tot=qm-xz; if(tot<0) tot=-tot; } ite=it; ite++; if(ite!=s.end()) { hm=*ite; sum=hm-xz; if(sum<0) sum=-sum; } else { cz[i]=tot; continue; } if(tot>sum) tot=sum; cz[i]=tot; tot=inf; sum=inf; hm=inf; qm=inf; } for(int i=1;i<=n;i++) printf("%d\n",cz[i]); return 0;}
%%%sys
2 0
- 洛谷 https://www.luogu.org/problem/show?pid=T574
- 洛谷 https://www.luogu.org/problem/show?pid=T575
- 洛谷P1011 车站(题目来源:https://www.luogu.org/problem/show?pid=1011)
- 洛谷 P3378 【模板】堆(https://www.luogu.org/problem/show?pid=3378)
- 洛谷 P3383 【模板】线性筛素数(https://www.luogu.org/problem/show?pid=3383)
- 洛谷P1025 数的划分(题目来源https://www.luogu.org/problem/show?pid=1025)
- Dragons https://www.bnuoj.com/v3/problem_show.php?pid=26407
- https://www.virtualbox.org/wiki/Linux_Downloads
- ZK 网址 https://www.zkoss.org/
- https://www.tensorflow.org/get_started/mnist/pros
- https://www.kernel.org/doc/Documentation/PCI/
- problem.php?pid=513
- luogu 1001 A+B problem
- http://www.lihuasoft.net/news/show.php?id=4395
- Problem D. Fashion Show
- https://www.usenix.org/legacy/event/sec11/tech/slides/enck.pdf
- 测试网站兼容性:http://browsershots.org/ 和https://www.browserstack.com/
- 无法连接到“https://www.nuget.org/api/v2/”中指定的源
- 51nod-【1013 3的幂的和】
- 【题】【(堆/线段树/树状数组优化DP)/图论】NKOJ 3485 数据
- 面向对象之依赖、组合、聚合
- eclipse中查看源码方法
- 单向散列加密,对称加密,非对称加密
- 洛谷 https://www.luogu.org/problem/show?pid=T574
- 代码规范工具-Checkstyle使用手册
- 一种简单粗暴的数据层网络缓存(二)实现方案
- 11月第二周周报
- Java 深究字符串String类(2)之重写toString()方法无意识递归
- anddroid 图标大小
- 嵌入式linux开发面试题解析——C语言部分
- 自定义下拉刷新上拉加载控件(SwipeRefreshLayout + recyclerView)
- 向SVN提交项目时显示提交成功却没有上传