st

SA & SAM

删除回忆录丶 提交于 2019-12-23 22:13:54
后缀数组SA \(sa[i]\) 与 \(rk[i]\) \(sa[i]\) 表示排名为 \(i\) 的后缀是哪一个(在原串中开头位置)。 \(rk[i]\) (或 \(rank[i]\) )表示开头位置是 \(i\) 的后缀的排名。 两者是互相映射关系,即 \(sa[rk[i]] = i\) 。 后缀排序(倍增) 假设我们求出了只考虑长度为 \(w\) 的每一个后缀的前缀的 \(sa\) 和 \(rk\) ,怎么求考虑长度为 \(2w\) 的每一个后缀的前缀的 \(sa\) 和 \(rk\) . 对于两个后缀 \(i\) 和 \(j\) , 由于我们求出了在 \(w\) 下的 $sa $ 和 \(rk\) ,实际上可以通过比较两个二元组 \((rk_i,rk_{i+w}),(rk_j, rk_{j+w})\) 来确定大小关系,这里定义一个后缀 \(i\) 的两维度:第一维字符串 \([i...i+w-1]\) ,第二维字符串 \([i+w,i+2w-1]\) 。 为了方便实现以及减小常数,我们开一个辅助数组 \(tmp[i]\) 表示上一轮排序(长度 \(w\) ),排名为 \(i\) 的后缀的长度为 \(w\) 的前缀对应的是现在的哪一个后缀的第二维, \(tmp\) 可以由 \(w\) 下的 \(sa\) 求得。 cnt = 0; for (int i = n - w + 1

loj 1271

非 Y 不嫁゛ 提交于 2019-12-23 16:31:58
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26981 思路:题目的意思是求给定的起点到终点的最短路径序列,并且这个序列的字典顺序最小。我们可以先求最短路,然后对那些在最短路上的点进行深度优先搜索。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 #include<queue> 7 #include<set> 8 using namespace std; 9 10 const int MAXN=55555; 11 const int inf=1<<30; 12 vector<int>g[MAXN],vet,ans; 13 int n,st,ed; 14 15 int dist[MAXN]; 16 bool mark[MAXN]; 17 18 struct Node{ 19 int v,d; 20 Node(int vv,int dd){ 21 v=vv,d=dd; 22 } 23 bool operator < (const Node &p) const { 24 if(p.d!=d)return p.d<d; 25 return p.v

强化学习(9):TRPO、PPO以及DPPO算法

拟墨画扇 提交于 2019-12-22 11:42:13
本文主要讲解有关 TRPO算法、PPO 算法、PPO2算法以及 DPPO 算法的相关内容。 一、PPO 算法 PPO(Proximal Policy Optimization) 是一种解决 PG 算法中学习率不好确定的问题的算法,因为如果学习率过大,则学出来的策略不易收敛, 反之,如果学习率太小,则会花费较长的时间。PPO 算法利用新策略和旧策略的比例,从而限制了新策略的更新幅度,让 PG 算法对于稍微大一点的学习率不那么敏感。 为了判定模型的更新什么时候停止,所以 PPO 在原目标函数的基础上添加了 KL 散度部分,用来表示两个分布之间的差别,差别越大值越大,惩罚也就越大。所以可以使两个分布尽可能的相似。PPO 算法的损失函数如下: J P P O θ ′ ( θ ) = J θ ′ ( θ ) − β K L ( θ , θ ′ ) J_{PPO}^{\theta'}(\theta)=J^{\theta'}(\theta)-\beta KL(\theta,\theta') J P P O θ ′ ​ ( θ ) = J θ ′ ( θ ) − β K L ( θ , θ ′ ) J θ ′ ( θ ) = E ( s t , a t ) ∼ π θ ′ [ p θ ( a t ∣ s t ) p θ ′ ( a t ∣ s t ) A θ ′ ( s t , a t ) ] J

1027 Colors in Mars (20 分)

纵然是瞬间 提交于 2019-12-21 05:16:04
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red , the middle 2 digits for Green , and the last 2 digits for Blue . The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values. Input Specification: Each input file contains one test case which occupies a line containing the three decimal color values.

pandas subplots in a loop

纵饮孤独 提交于 2019-12-20 02:35:38
问题 I have this code which plots well my plots in a 1 row and 6 columns I tried unsuccessfully to plot it in a 2x3 or 3x2 Is there something I'm missing in the .plot() implementation of pandas ? fig, axes = plt.subplots(nrows=1, ncols=6) spfvL = [6, 11, 22, 33, 44, 55] for j, i in enumerate(spfvL): df['spfv' + str(i)] = pd.rolling_std(df['r VIX'], i)*np.sqrt(252) res = smf.ols(formula='spfv'+ str(i)+' ~ Q(\'VIX Index\')', data=df).fit() df['pred'+ str(i)] = better_predict(res, df) df.loc[:,['pred

C++标准模板库(STL)之Set

拈花ヽ惹草 提交于 2019-12-17 06:22:35
1、Set的用法 Set:集合,一个内部自动有序而且不重复元素的容器。使用set,要加头文件 #include<set>和using namespace std;    1.1、Set的定义 set<typename> name; set<int> name; set<double> name; set<char> name; set<Node> name;//Node是结构体类型 set<typename> Arrayname[arraySize];//set<int> a[100];a[0]~a[99]的每一个都是一个set容器。 /* 定义和写法和vector基本一样,同样typename可以是任何基本类型,结构体,STL容器类型。 同样,typename是容器的时候,>>后要加空格,避免编译器当成位运算出错。 */   1.2、set容器内元素的访问    set只能通过迭代器iterator访问 set<typename>::iterator it;//typename对应定义set时的类型。 set<int>::iterator it;   因为除了vector和string之外的STL的容器都不支持以下标的方式访问。 #include<stdio.h> #include<set> using namespace std; int main() { set<int>

ST MCU的UID

浪子不回头ぞ 提交于 2019-12-16 10:55:33
ST MCU芯片中的绝大部分都内置一串96位唯一标识码【unique ID】 上面说了ST MCU芯片中的绝大部分都带UID,也就是说并非所有ST MCU芯片都带它。到底谁带谁不带,从各自芯片数据手册的首页即可确认。如果首页没有明确写明,就表示该芯片没有UID或者说即使相应地址有数据但不保证其唯一性。 比方在STM8系列中,STM8S0XX、STM8L0XX系列芯片就不带UID的。 在STM32家族中,STM32F0系列中的STM3F030子系列、STM32F070子系列也是不带UID的【如果此处说错,遵照数据手册所言】,而STM32F042、STM32F071、STM32F031、STM32F051等是带UID的。这点也不用太花心思记它,知道去芯片数据手册首页核查就好。 该UID对用户来讲是只读的,在一些对数据具有唯一性要求、数据加密操作等场合可以派上用场。ST MCU芯片中的这个UID 是对整串92位数据保证唯一性,如果你截取其中一部分就不保证唯一性了。 STM32芯片UID的详细描述是在各系列的参考手册里。比方,STM32F0系列UID介绍如下。 大致内容就是芯片WAFER的坐标信息、编号信息、产品批号信息等多个数据组合在一起的。关于UID的描述,在STM8数据手册里描述更为直观点,截图如下: 至于对该UID数据的读取,没啥特别的。先从ST

CF1277D Let's Play the Words?

坚强是说给别人听的谎言 提交于 2019-12-16 01:21:37
思路: 字符串其实只有0...0, 0...1, 1...0, 1...1四种。 实现: 1 #include <bits/stdc++.h> 2 using namespace std; 3 set<string> st[4]; 4 bool work(set<string>& a, set<string>& b, map<string, int>& mp, vector<int>& res) 5 { 6 int d = a.size() - b.size(); 7 for (auto it: a) 8 { 9 if (res.size() == d / 2) break; 10 string tmp = it; 11 reverse(tmp.begin(), tmp.end()); 12 if (b.count(tmp)) continue; 13 res.push_back(mp[it]); 14 } 15 return res.size() >= d / 2; 16 } 17 int main() 18 { 19 int t; cin >> t; 20 while (t--) 21 { 22 for (int i = 0; i < 4; i++) st[i].clear(); 23 int n; cin >> n; 24 map<string, int> mp; 25

HD1254推箱子 AC代码——bfs的实现

时光毁灭记忆、已成空白 提交于 2019-12-14 00:02:05
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 题目描述: 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不能拉箱子,因此如果箱子被推到一个角上(如图2)那么箱子就不能再被移动了,如果箱子被推到一面墙上,那么箱子只能沿着墙移动. 现在给定房间的结构,箱子的位置,搬运工的位置和箱子要被推去的位置,请你计算出搬运工至少要推动箱子多少格. Input 输入数据的第一行是一个整数T(1<=T<=20),代表测试数据的数量.然后是T组测试数据,每组测试数据的第一行是两个正整数M,N(2<=M,N<=7),代表房间的大小,然后是一个M行N列的矩阵,代表房间的布局,其中0代表空的地板,1代表墙,2代表箱子的起始位置,3代表箱子要被推去的位置,4代表搬运工的起始位置. Output 对于每组测试数据,输出搬运工最少需要推动箱子多少格才能帮箱子推到指定位置,如果不能推到指定位置则输出-1. Sample Input 1 5 5 0 3 0 0 0 1 0 1 4 0 0 0 1 0 0 1 0 2 0 0 0 0 0 0 0 Sample Output 4 题目链接 http:

Sorting linked list alphabetically in c [duplicate]

折月煮酒 提交于 2019-12-13 04:39:27
问题 This question already has answers here : Sorting a linked list in C (6 answers) Closed 5 years ago . I would to ask you, if it is possible to simple sort alphabetically linked list with names? I think that it is possible, but i dont know how. Can you help me with that? I will be very thankful. "i" pressed should scan new name and add this name to linked list and then to sort this list alphabetically "d" pressed should to display entire sorted list "k" pressed program ends I did this with