Educational Codeforces Round 20 B
Description
You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).
Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.
9
2 1 0 3 0 0 3 2 4
2 1 0 1 0 0 1 2 3
5
0 1 2 3 4
0 1 2 3 4
7
5 6 0 1 -2 3 4
2 1 0 1 2 3 4
题意:求距离0最近的距离
解法:找距离最近的0,可能是左边或者右边的0,取最近的
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
vector<ll>x,y;
ll n;
ll num[];
ll a[];
long long sum;
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>num[i];
if(num[i])
{
x.push_back(i);
}
else
{
y.push_back(i);
}
}
for(int i=;i<x.size();i++)
{
int pos=lower_bound(y.begin(),y.end(),x[i])-y.begin();
//cout<<pos<<endl;
if(pos==) pos++;
if(pos<=y.size()&&pos>=)
{
a[x[i]]=min(abs(x[i]-y[pos]),abs(x[i]-y[pos-]));
}
}
for(int i=;i<=n;i++)
{
cout<<a[i]<<" ";
}
return ;
}
Educational Codeforces Round 20 B的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Educational Codeforces Round 20 D. Magazine Ad
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...
- Educational Codeforces Round 20 C(math)
題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 C 数学/贪心/构造
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 C. Maximal GCD
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 B. Distances to Zero
B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 20 A. Maximal Binary Matrix
A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
随机推荐
- ribbon负载均衡进行服务消费
相同服务以不同端口形式注册到eureka上,ribbon从eureka上获取冰进行服务消费,会偶现如下现象: I/O error on GET request for "http://COM ...
- CentOS挂载优盘
插入优盘前: [root@centOS5 mnt]# fdisk -l Disk /dev/hdd: bytes heads, sectors/track, cylinders Units = cyl ...
- this、call和apply、bind
this关键字: JavaScript的this关键字,总是指向一个对象,具体指向哪个对象,是根据运行时函数指向环境动态绑定的.简单来说,this就是谁调用指向谁.具体使用中,this的指向,大致可以 ...
- 在vs2005中添加lib库的方法
方法一:在用到lib的地方加上 //强烈推荐这种方法.#pragma comment(lib,"libname.lib") 方法二: 点击菜单命令 “项目/属性”, ...
- Delphi中取得汉字的首字母简单方法(十分巧妙)
//从朝闻道的博客里转载,原文定义AHzStr: String,发现结果为空,后来改成AHzStr: AnsiString就可以了 function GetHzPy(const AHzStr: Ans ...
- HBase运维和优化
管理工具 HBase ShellHBase Shell是HBase组件提供的基于JRuby IRB的字符界面的交互式客户端程序,通过HBase Shell可以实现对HBase的绝大部分操作 通过hel ...
- Vijos P1389婚礼上的小杉
背景 小杉的幻想来到了经典日剧<求婚大作战>的场景里……他正在婚礼上看幻灯片,一边看着可爱的新娘长泽雅美,一边想,如果能再来一次就好了(-.-干嘛幻想这么郁闷的场景……). 小杉身为新一代 ...
- HDU4292 Food —— 最大流 + 拆点
题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- oracle 删除用户命令和部分表空间操作
删除用户 drop user user_name cascade; 建立表空间 CREATE TABLESPACE data01DATAFILE '/oracle/oradata/db/DATA01. ...
- Oracle:ORA-01790: expression must have same datatype as corresponding expression
今天有现场报sql错误,错误sql语句 类似 select * from tableA where (exists 条件A or exists 条件B), 单独执行 select * f ...