题目链接:https://vjudge.net/problem/CodeForces-803B#author=0 题意: 给你一个数组,其中至少包括一个0,求每一个元素距离最近一个0的距离是多少. 样例: Input 92 1 0 3 0 0 3 2 4 Output 2 1 0 1 0 0 1 2 3 思路:把每一个0的下标都放进一个新数组中,然后枚举每一个数组pos,用二分查找pos在新数组中刚好大于等于pos的那个index,然后再和前后的index比较下取最小值,然后即得出答案. 作者的…
803B - Distances to Zero 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 200005 int ai[maxn],bi[maxn],ci[maxn],n; inline void in(int &now) { ; ') Cget=…
Distances to Zero 题目链接:http://codeforces.com/problemset/problem/803/B 题目大意: 给一串数字,求每个数字到离他最近数字0的距离...水题 例:2 1 0 3 0 0 3 2 4 输出:2 1 0 1 0 0 1 2 3 思路: 每次读入一个数字要么是0要么不是0 ①如不是0 到0最近距离等于左边那位距离+1 ②如是0 本身距离为0 向左循环,如果到现在输入0距离 小于 到上一个0的距离 就更新距离,到不小于位置即可 AC代码:…
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a.    然后求出这些学生能买自行车的最大数量,并且求当买下最大自行车数量时,总体花费私己钱的最少的钱. 我先来说以下二分搜索模板: //右值点不能取到的情况 int binary_search(vector<int>& nums,int left,int right, int targe…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. 思路: 转化为判定性问题.二分天数. 然后贪心,在规定天数以内,最后一天通过即可.需要保证每一科最后一天之前剩下还没考试的科目都来得及复习.(同时注意要要加上考试时间) 最后还要判定是不是所有的科目都通过了. */ #include<bits/stdc++.h> using namespace…
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{d[i][j-1], d[i+2^j-1][j-1]} RMQ的ST算法: void ST() //初始化 { memset(RMQ,,sizeof(RMQ)); ;i<=n;i++) RMQ[i][]=a[i]; ;(<<j)<=n;j++) ;i+(<<j)-<=…
题意:有n个箱子形成的堆,现在有m个学生,每个学生每一秒可以有两种操作: 1: 向右移动一格 2: 移除当前位置的一个箱子 求移除所有箱子需要的最短时间.注意:所有学生可以同时行动. 思路:二分时间,判断当前限制的时间是否可以移除完所有箱子.那么如何判断呢? 设lim表示当前的时间限制,走到第个堆花费秒,从第n个堆开始处理,第i个堆需要的学生数是,可能,那么就剩余的箱子可以拿,既然是从1走到i那么,一定可以移除前面的箱子,这样一直就行.复杂度O(n) AC代码 #include <cstdio>…
大意: 给定数组$a$, 每次操作使最大元素减小1最小元素增大1, 求k次操作后最大值与最小值的差. 二分出k次操作后最大值的最小值以及最小值的最大值, 若和能平分答案即为$max(0,R-L)$, 否则为$max(1,R-L)$ #include <iostream> #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <…
You are given two arrays of integers a and b. For each element of the second arraybj you should find the number of elements in array a that are less than or equal to the value bj. Input The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — t…