CF1237D Balanced Playlist】的更多相关文章

思路:假设从第i首歌开始听,结束位置为j,那么从第i+1首歌开始听,结束位置一定不早于j.可以用反证法证明.想到这一点,就不难解决了. 实现: #include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; ; ]; int log2(int x) { ; ; res++; } return res; } void init(int n) { ; i < n; i++) st[i][] = a[i]; ;…
CF1237D Balanced Playlist 题意 有一个长度为\(n\)(\(n\leq 10^5\))的循环播放歌单,每首歌有一个优秀值\(a_i\)(\(a_i\leq 10^9\)). 听歌时选一首歌开始,如果某一首歌\(x\)的优秀值的两倍小于当前听过的歌中优秀值最大的,那么会在听完\(x\)之前停止听歌. 对于每首歌\(i\),求\(c_i\)表示如果从它开始听,最多听完几首歌,如果有重复的算多首.如果从一个位置开始能无限听下去,那么\(c_i=-1\). 题解 首先发现当一个…
题意:给定一个n首歌的播放列表,第i首的值为a[i],听完第i首会回到第1首 现在从每首开始往下,记录听过的最大值,如果当前听的值严格小于听过最大值的一半则停止 问从每首歌开始往下听能听几首,不会停止则输出-1 n<=1e5,1<=a[i]<=1e9 思路:会D不会C,D的写法还奇渣无比…… 因为是环形所以先复制粘贴一遍,然后按a[i]从大到小排个序 对于每个出发点now,设在now之后且离now最近的值比他a[now]的点为nxt,在到达nxt之前其听过的最大值一定为a[now] 如果…
传送门 首先显然的,如果一个位置开始播放了两圈还没结束,那么就永远不会结束 先考虑位置 $1$ 开始播放,用一个 $multisetset$ 维护一下当前听的所有歌,直到某一首歌 $r$ 不合法了就停止,此时播放的区间即为位置 $1$ 开始的答案 然后考虑从位置 $2$ 开始播放时和从位置 $1$ 开始播放有什么变化,显然播放的歌曲一定可以到 $r$ (反证法容易证明),并且 $multiset$ 里少了一首位置 $1$ 的歌 那么直接把 $multiset$ 更新一下,然后继续模拟过程直到下一…
传送门 A. Balanced Rating Changes 签到,分正负搞一下就行. B. Balanced Tunnel 题意: 给出\(n\)辆车的进洞顺序和出洞顺序,问有多少量车实现了洞中超车. 思路: 对于进洞的车\(i\),找到其出洞之前所有的车,若有车还未进洞,则那辆车实现了超车. 对于出洞序列维护一个指针\(j\),可以证明,任一时刻\(j\)之前的车都处于超车和没超车两种状态,也就是说\(j\)是单调不减的. 然后就类似于双指针搞下就行. Code #include <bits…
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more tha…
Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一层都有两个子节点: 2. Complete类型: 除最下面一层外为Full类型, 但是最下面一层最所有子节点靠左: 3. Balanced类型: 左右两个子树的长度相差小于等于一: /** * Definition of TreeNode: * public class TreeNode { * public…
110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 很早以前做的了  准…
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 比较左子树和右子树的深度,取小的那个返回上来,并+1. 需要注意的是如果没有左子树或右子树.那么无条件取存在的那一边子树深…
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 思路: 1) 计算结点的高度,但这个有重复计算 package…