st

洛谷 P3865 ST表

走远了吗. 提交于 2020-02-04 13:12:17
ST表 ST表的功能很简单 它是解决RMQ问题(区间最值问题)的一种强有力的工具 它可以做到 O(nlogn) 预处理, O(1) 查询最值 是一种处理静态区间可重复计算问题的数据结构,一般也就求求最大最小值辣。 ST表的思想是先求出每个[i, i + 2^k)的最值。 注意到这样区间的总数是O(N log N)的. 预处理 不妨令f i,j 为[i, i + 2^j)的最小值。 那么首先fi,0的值都是它本身。 而f i,j = min(f i,j−1 , f i+2^j−1,j−1 ) 这样在O(N log N)的时间内就处理好了整个ST表 询问 比如我们要询问[l, r]这个区间的最小值. 找到最大的k满足2^k ≤ r − l + 1. 取[l, l + 2^k), [r − 2^k + 1, r + 1)这两个区间。 注意到这两个区间完全覆盖了[l, r],所以这两个区间最小值 较小的一个就是[l, r]的最小值。 注意到每次询问只要找区间就行了,所以复杂度是O(1). 解释一下数组含义: ST[j][i]为从j开始的长度为2^i的区间的最大值 Log[x]为比x小的最大的2^y 的y值(或者说是log x 下去整 ) 代码: #include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip>

C++ 缺少 类模板 的参数列表

笑着哭i 提交于 2020-02-03 00:57:47
@C++ 缺少 类模板 的参数列表 编写代码的时候,编译器提示缺少std::list参数列表,该怎么办。我是VS的工具。 # include <iostream> # include <vector> # include <list> using namespace std ; using namespace std :: list ; vector < int > twoSum ( vector < int > & nums , int target ) { // 备份原数组 vector < int > tmp ; for ( int i = 0 ; i < nums . size ( ) ; i ++ ) tmp . push_back ( nums [ i ] ) ; // 对原数组进行排序 std :: list :: sort ( nums . begin ( ) , nums . end ( ) ) ; vector < int > res ; // 头尾双向遍历 int st = 0 ; int en = nums . size ( ) - 1 ; while ( st < en ) { while ( nums [ en ] + nums [ st ] > target && en > st ) en -- ; if ( en == st ) break ; if

INT128

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-02 23:58:34
#include<bits/stdc++.h> #define DEBUG cerr << "Call out: " << __func__ << "\t" << "Line: " << __LINE__ << "\t :" using namespace std; class INT128{ public: #define OPERATOR 9223372036854775808ull //(1 << 63) #define HERE (*this) unsigned long long HighPart, LowPart; INT128(){ HighPart = 0; LowPart = 0; } INT128(long long p) { HighPart = 0; LowPart = 0; if (p >= 0) LowPart = p; else LowPart = p, HERE.rev(); } INT128(long long p,long long q){ HighPart = p; LowPart = q; } void print(){ cout << (bitset<64>)HighPart << ' ' << (bitset<64>)LowPart; } void printH(){ cout << hex << HighPart << LowPart

c++学习笔记(三)

这一生的挚爱 提交于 2020-02-02 23:35:27
STL (Standard Template Library) 标准模版库 一、sort 二、二分查找 三、排序容器 1. multiset 要 #include ; 用法1: multiset st; 定义了一个multiset变量st,st里面可以存放T类型的数据,并且能 自动排序 排序的规则: 表达式 a<b 为true,则a排在b前面,否则b排a前面 (从小到大) st.insert(i) 添加元素 st.find(i) 查找和i相等的元素,返回值是迭代器 st.erase(i) 删除元素 st.begin()返回指向第一个元素的迭代器 st.end()返回指向最后一个元素 后面 的迭代器 st.lower_bound(i)返回指向下界的迭代器 st.upper_bound(i) 返回指向上界的迭代器 迭代器(类似指针) 要访问multiset得通过迭代器 定义迭代器 multiset ::iterator p; p是迭代器,用于指向multiset中的元素。 迭代器可++,--,!=,==。 但是不可以加减一个整数,也不可以相减、比大小。 #include<iostream> #include<set> using namespace std; int main() { int a[10] = {1,14,13,23,18,42,8,7,8,6},i; multiset

我的强化学习极简笔记

余生长醉 提交于 2020-02-02 03:27:31
强化学习极简笔记 文章目录 强化学习极简笔记 动态规划 模型 迁移 策略 值函数 Bellman 方程 算法 Markov 决策 --- 不确定动态规划 模型 迁移 策略 奖励 状态值函数 状态行为值函数 Bellman 方程 基模型 策略迭代算法 强化学习 基于值函数 (模型未知) 时间差分TD Sarsa( λ \lambda λ ) QLearning 值函数逼近 Sarsa 算法 关键字: 模型 迁移 奖励 策略 值函数 状态值函数 状态-动作值函数 Bellman 方程 TD 算法 Sara算法 Q学习 同/异策略 动态规划 强化学习是基于动态规划的。 模型 函数模型 ( S , A , f , π , r , γ ) (S, A,f, \pi, r, \gamma) ( S , A , f , π , r , γ ) S S S :状态集合 A A A : 动作集合 f : S × A → S f:S\times A\to S f : S × A → S 状态转移函数 π \pi π : 策略 r : S × A → R r:S\times A\to\R r : S × A → R 动作奖励 γ \gamma γ : 折扣因子 当 f , π , r f,\pi,r f , π , r 为转移概率时,是非确定模型 图论模型(没有动作集) ( G = ( V , E )

刷题20. Valid Parentheses

我的梦境 提交于 2020-02-01 09:22:38
一、题目说明 这个题目是20. Valid Parentheses,简单来说就是括号匹配。在学数据结构的时候,用栈可以解决。题目难度是Medium。 二、我的解答 栈涉及的内容不多,push、pop、top,。 我总共提交了3次: 第1次:Runtime Error,错误原因在于pop的时候,未判断栈是否为空。 第2次:Wrong Answer,这个是“眼大”疏忽导致的,我写的时候只考虑了 ()[] 未考虑 {} 。 第3次:终于正确了,性能还可以: Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Parentheses. Memory Usage: 8.5 MB, less than 73.64% of C++ online submissions for Valid Parentheses. 代码如下: #include<iostream> #include<stack> using namespace std; class Solution{ public: bool isValid(string s){ stack<char> st; char ch,curr; for(int i=0;i<s.size();i++){ curr = s[i]; if(curr=='(' ||

PAT 甲级 1130 Infix Expression

删除回忆录丶 提交于 2020-01-31 13:03:06
https://pintia.cn/problem-sets/994805342720868352/problems/994805347921805312 Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integer N ( ≤ 20) which is the total number of nodes in the syntax tree. Then N lines follow, each gives the information of a node (the i-th line corresponds to the i-th node) in the format: data left_child right_child where data is a string of no more than

【JZOJ2758】【SDOI2012】走迷宫(labyrinth)

旧巷老猫 提交于 2020-01-30 04:09:16
╰( ̄▽ ̄)╭ Morenan 被困在了一个迷宫里。 迷宫可以视为 N 个点 M 条边的有向图,其中 Morena n处于起点 S , 迷宫的终点设为 T 。 可惜的是 , Morenan 非常的脑小 , 他只会从一个点出发随机沿着一条从该点出发的有向边 , 到达另一个点 。 这样 , Morenan 走的步数可能很长 , 也可能是无限,更可能到不了终点。 若到不了终点,则步数视为无穷大。 但你必须想方设法求出 Morenan 所走步数的期望值。 (⊙ ▽ ⊙) 一开始看着道题,就觉得是tarjan缩点后,转化成DAG上的问题。 当原图是DAG时 设 f i 表示第 i 个点走到终点的距离。 容易有 f i = ∑ j ∈ n e x t ( i ) 1 | n e x t ( i ) | ∗ ( f j + 1 ) , 其中 n e x t ( i ) 是 i 的后继集合。 很容易使用拓扑排序来完成动态规划。 当原图是一般的有向图时 利用 t a r j a n 算法可以把图中的强连通分量找出来。 对于任意一个强连通分量,我们利用高斯消元来求解出强连通分量中的每个点的 f 值。 套上拓扑排序,就能够解决。 时间复杂度为 O ( n ∗ L 3 ) ,其中 L 为最大强连通分量的大小。 实际时间复杂度则远远不到。 ( ̄~ ̄) 高斯(gauss)消元: 1.目标 对 n 条 n

总结一下查找与排序的程序算法

一世执手 提交于 2020-01-29 00:22:59
前言: 总结一波!!! 一、查找 1.顺序查找 int Search_Seq( SSTable ST , KeyType key ){ //若成功返回其位置,否则返回0 ST.R[0].key =key; for( i=ST.length; ; i-- ) if( ST.R[i].key==key ) return i; } 2.折半查找 int Search_Bin(SSTable ST,KeyType key){ //若找到,则函数值为该元素在表中的位置,否则为0 low=1;high=ST.length; while(low<=high){ mid=(low+high)/2; if(key==ST.R[mid].key) return mid; else if(key<ST.R[mid].key) high=mid-1; //前半子表查找 else low=mid+1; //后半子表查找 } return 0; //表中不存在待查元素 } 3.二叉排序树查找 BSTree SearchBST(BSTree T,KeyType key) { if((!T) || key==T->data.key) return T; else if (key<T->data.key) return SearchBST(T->lchild,key); //在左子树中继续查找 else

G4 开发资源

眉间皱痕 提交于 2020-01-27 15:50:08
STM32CubeMX_STM32初始化代码生成器 https://www.stmcu.com.cn/Designresource/design_resource_detail/file/478391/lang/EN/token/c29454c6b73b8423261debf8c12f99c9 https://www.stmcu.com.cn/Index/search?search_keywords=STM32CubeMX STM32CubeG4_软件开发包 https://www.stmcu.com.cn/Designresource/design_resource_detail/file/478391/lang/EN/token/c29454c6b73b8423261debf8c12f99c9 # STM32CubeG4 MCU Firmware Package **STM32Cube** is an STMicroelectronics original initiative to ease the developers life by reducing efforts, time and cost. **STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive