├── .gitignore ├── Makefile ├── README.md ├── SCL-collection ├── Dracarys.zip ├── DracarysA │ ├── dom.tex │ ├── geometry_ex.tex │ ├── main.aux │ ├── main.log │ ├── main.pdf │ ├── main.synctex.gz │ ├── main.tex │ ├── main.toc │ ├── main_bak.pdf │ ├── ntt.tex │ ├── simplex.tex │ ├── tmp │ ├── tmp.cpp │ └── vimrc.vim ├── Dracarys_wf.docx ├── Dracarys_wf.zip ├── Dracarys_wf │ ├── DC3.cpp │ ├── DancingLinks.cpp │ ├── Hopcroft.cpp │ ├── KM.cpp │ ├── NTT.cpp │ ├── Pell方程.cpp │ ├── Romberg.cpp │ ├── nlogn半平面交.cpp │ ├── 三维几何操作合并.cpp │ ├── 三维凸包(n^2).cpp │ ├── 三维凸包求重心.cpp │ ├── 三维旋转操作.cpp │ ├── 三角形的心.cpp │ ├── 二次剩余.cpp │ ├── 二维几何.cpp │ ├── 动态最小生成树.cpp │ ├── 动态树.cpp │ ├── 后缀数组(nlogn).cpp │ ├── 后缀自动机.cpp │ ├── 启发式分解.cpp │ ├── 回文串manacher.cpp │ ├── 圆的面积模板(n^2logn).cpp │ ├── 多边形与圆面积交.cpp │ ├── 字符串最小表示.cpp │ ├── 带花树.cpp │ ├── 无向图最小割.cpp │ ├── 最大团.cpp │ ├── 最小覆盖球.cpp │ ├── 最远点对.cpp │ ├── 极大团计数.cpp │ ├── 直线和凸包交点(返回最近和最远点).cpp │ ├── 素数判定.cpp │ ├── 线性规划.cpp │ ├── 经纬度求球面最短距离.cpp │ ├── 蔡勒公式.cpp │ └── 长方体表面两点最短距离.cpp ├── MahoushojoMiracle-Enkannokotowari.pdf ├── Mithril_wf.docx ├── Mithril_wf.pdf ├── Musou_SCL_Final.docx ├── Musou_SCL_Final.pdf ├── SuperNova │ ├── .main.tex.swl │ ├── .main.tex.swm │ ├── .main.tex.swn │ ├── .main.tex.swo │ ├── .几何公式.tex.swo │ ├── 3D_Geo.tex │ ├── 3D_Geo.tex~ │ ├── BabyStep.tex │ ├── DC3.tex │ ├── Dancing.tex │ ├── Edmonds.tex │ ├── Edmonds.tex~ │ ├── GY's lib │ │ ├── SCL_FFT+DVCQ.cpp │ │ ├── SCL_FFT+DVCQ.tex │ │ ├── SCL_KDTree.cpp │ │ ├── SCL_KMP.cpp │ │ ├── SCL_KMP.tex │ │ ├── SCL_intersect_circle_polygon.cpp │ │ ├── SCL_intersect_circle_polygon.cpp~ │ │ ├── SCL_intersect_circle_polygon.tex │ │ ├── SCL_intersect_circle_polygon.tex~ │ │ ├── SCL_str_cyc_min_rep.cpp │ │ ├── SCL_str_cyc_min_rep.tex │ │ ├── sgu345.cpp │ │ ├── sgu345.tex │ │ └── sgu345.tex~ │ ├── Geo-convexhull.tex │ ├── Geo-diameter.tex │ ├── Geo │ │ ├── basic │ │ ├── basic.cpp │ │ └── 球面.cpp │ ├── Geo3.tex │ ├── Hopcroft.tex │ ├── Hopcroft.tex~ │ ├── KDTree_GY.tex │ ├── KDtree.tex │ ├── KM.tex │ ├── KM_GY.tex │ ├── LCT.tex │ ├── MDSTN3.tex │ ├── MDSTN3.tex~ │ ├── MDSTNlogN.tex │ ├── MDSTNlogN.tex~ │ ├── Manacher.tex │ ├── Manacher.tex~ │ ├── MillerRabbin2.tex │ ├── MillerRabbin2.tex~ │ ├── SAM_GY.tex │ ├── SCC.tex │ ├── SCL_FFT_DVCQ.tex │ ├── SCL_KMP.tex │ ├── SCL_KM_sgu206.cpp │ ├── SCL_cir_k_inter.tex │ ├── SCL_farmland_GY.tex │ ├── SCL_intersect_circle_polygon.tex │ ├── SCL_str_cyc_min_rep.tex │ ├── Simpson │ │ ├── .CIRU.cpp.swp │ │ └── CIRU.cpp │ ├── S三维旋转操作.tex │ ├── S三维旋转操作.tex~ │ ├── S基本操作.tex │ ├── S基本操作.tex~ │ ├── Tips.tex │ ├── acautomaton.tex │ ├── aczidongji_shy.tex │ ├── amppzstd.tex │ ├── amppzstd.tex~ │ ├── astar_shy.tex │ ├── b.cpp │ ├── binary-heap.tex │ ├── c │ ├── c.cpp │ ├── c.in │ ├── c_ref.tex~ │ ├── cheat sheet │ │ └── cheat.pdf │ ├── crt.tex │ ├── decomposition.tex │ ├── dijkstra.tex │ ├── farmland │ │ ├── a.cpp │ │ └── a.in │ ├── farmlandLYP.tex │ ├── km_邻接矩阵.tex │ ├── km_链表.tex │ ├── language_ref.tex │ ├── leftist-tree.tex │ ├── main.aux │ ├── main.log │ ├── main.pdf │ ├── main.tex │ ├── main.tex~ │ ├── main.toc │ ├── maxflow.tex │ ├── mincostflow.tex │ ├── missfont.log │ ├── n次剩余.tex │ ├── pinhengshu.tex │ ├── prefixInverse.tex │ ├── q.log │ ├── rho.tex │ ├── segment-tree.tex │ ├── sgu345.tex │ ├── splay.tex │ ├── suffix-array.tex │ ├── suffix-automaton.tex │ ├── tmp.cpp │ ├── tmp.in │ ├── tmp2 │ ├── tmp2.cpp │ ├── tmpSGU332 │ │ ├── a.cpp │ │ └── a.in │ ├── treap.tex │ ├── vimrc.tex │ ├── vimrc.tex~ │ ├── z.tex │ ├── zkw.tex │ ├── 三维几何 │ │ ├── copyseraphim.cpp │ │ ├── copyseraphim.cpp~ │ │ ├── copyseraphim.tex │ │ ├── tmp │ │ └── tmp.cpp │ ├── 三维凸包.tex │ ├── 三维凸包.tex~ │ ├── 三维旋转.cpp │ ├── 三维旋转.tex │ ├── 上下界无源汇可行流.tex │ ├── 上下界最大流.tex │ ├── 上下界最小流.tex │ ├── 上下界有源汇可行流.tex │ ├── 上下界流建图方法.tex │ ├── 上下界流建图方法.tex~ │ ├── 二次剩余.tex │ ├── 几何公式.log │ ├── 几何公式.tex │ ├── 几何公式.tex~ │ ├── 判断圆存在交集.cpp │ ├── 判断圆存在交集.tex │ ├── 判断多个圆是否存在交集 │ │ ├── a.cpp │ │ ├── a.in │ │ ├── a.out │ │ ├── b.cpp │ │ ├── b.out │ │ ├── check.sh │ │ └── gen.cpp │ ├── 半平面交.tex │ ├── 半平面交 │ │ ├── a.cpp │ │ └── a.tex │ ├── 后缀数组_shy.tex │ ├── 基本操作.cpp │ ├── 基本操作.tex │ ├── 基本操作.tex~ │ ├── 多少个点在多边形内.tex │ ├── 多项式求根.tex │ ├── 字符串的最小表示.tex │ ├── 字符串的最小表示 │ │ ├── a.cpp │ │ ├── a.in │ │ ├── a.out │ │ ├── check.sh │ │ ├── force.cpp │ │ ├── force.in │ │ ├── force.out │ │ └── gen.cpp │ ├── 弦图判定.tex │ ├── 弦图求团数.tex │ ├── 手工栈tarjan.tex │ ├── 斜线下格点统计.tex │ ├── 无向图最小割.cpp │ ├── 无向图最小割.tex │ ├── 最小圆覆盖.tex │ ├── 最小球覆盖.tex │ ├── 最小球覆盖 │ │ ├── .ser.cpp.swn │ │ ├── .ser.cpp.swo │ │ ├── .ser.cpp.swp │ │ ├── ser.cpp │ │ ├── ser.in │ │ └── 最小球覆盖.tex │ ├── 有根树的同构.tex │ ├── 杂知识.tex │ ├── 杂知识.tex~ │ ├── 极大团搜索.tex │ ├── 极大团计数.tex │ ├── 求某年某月某日星期几.tex │ ├── 求某年某月某日星期几 │ │ ├── a.cpp │ │ └── 求某年某月某日星期几.tex │ ├── 注意.tex │ ├── 点类.cpp │ ├── 点类.tex │ ├── 牛顿迭代开根号.tex │ ├── 牛顿迭代开根号 │ │ ├── a.cpp │ │ └── 牛顿迭代开根号.tex │ ├── 球面.cpp │ ├── 球面.tex │ ├── 直线凸包.tex │ ├── 直线凸包.tex~ │ ├── 线性递推.tex │ ├── 线性递推.tex~ │ ├── 线性递推 │ │ ├── a.cpp │ │ ├── x │ │ ├── x.cpp │ │ └── x.in │ ├── 长方体表面两点最短距离.tex │ └── 长方体表面两点最短距离 │ │ ├── a.cpp │ │ ├── a.in │ │ └── 长方体表面两点最短距离.tex ├── log └── template │ ├── ACM模板.pdf │ ├── SCL │ ├── Geo-basic.tex │ ├── Geo-convexcut.tex │ ├── Geo-convexhull.tex │ ├── Geo-diameter.tex │ ├── Geo.tex │ ├── KDtree.tex │ ├── KM.tex │ ├── LCT.tex │ ├── SCC.tex │ ├── acautomaton.tex │ ├── binary-heap.tex │ ├── crt.tex │ ├── decomposition.tex │ ├── dijkstra.tex │ ├── leftist-tree.tex │ ├── main.aux │ ├── main.log │ ├── main.pdf │ ├── main.synctex.gz │ ├── main.tex │ ├── main.toc │ ├── manacher.tex │ ├── maxflow.tex │ ├── mincostflow.tex │ ├── rho.tex │ ├── segment-tree.tex │ ├── splay.tex │ ├── suffix-array.tex │ ├── suffix-automaton.tex │ ├── treap.tex │ └── z.tex │ ├── SCL_gy.zip │ ├── SCL_gy │ ├── SCL_cir_k_inter.cpp │ └── SCL_farmland_GY.cpp │ ├── Seraphim模板.pdf │ ├── scl.docx │ ├── shy.zip │ ├── shy │ ├── Dancing.tex │ ├── aczidongji.cpp │ ├── aczidongji_shy.tex │ ├── astar.cpp │ ├── astar_shy.tex │ ├── hint.txt │ ├── km_邻接矩阵.tex │ ├── km_链表.tex │ ├── pinhengshu.cpp │ ├── pinhengshu.tex │ ├── zkw.tex │ ├── 上下界无源汇可行流.cpp │ ├── 上下界无源汇可行流.tex │ ├── 上下界最大流.cpp │ ├── 上下界最大流.tex │ ├── 上下界最小流.cpp │ ├── 上下界最小流.tex │ ├── 上下界有源汇可行流.cpp │ ├── 上下界有源汇可行流.tex │ ├── 二次剩余.txt │ ├── 后缀数组.cpp │ ├── 后缀数组_shy.tex │ ├── 弦图判定.cpp │ ├── 弦图判定.tex │ ├── 弦图求团数.cpp │ ├── 弦图求团数.tex │ ├── 手工栈tarjan.cpp │ ├── 手工栈tarjan.tex │ ├── 有根树的同构.tex │ └── 法雷数列.txt │ └── 浙大acm模板.doc ├── improve ├── Addon.tex ├── CycleLongest.cpp ├── DelaunayTriangulation.cpp ├── DominatorTree.cpp ├── FFT.cpp ├── FWT.cpp ├── Hungarian.cpp ├── LCT.cpp ├── LiuZhu.cpp ├── MaximumClique.cpp ├── MincostFlow.cpp ├── NTT.cpp ├── PlayWithConvex.cpp ├── SchreierSims.cpp ├── SuffixTree.cpp ├── SuffixTree2.cpp ├── Triangle.cpp └── 日期公式.cpp ├── main.aux ├── main.log ├── main.pdf ├── main.tex ├── main.toc ├── merge ├── 3DGeo.cpp ├── CircleArea.cpp ├── Geo2D.cpp ├── HalfPlaneIntersection.cpp ├── Manacher.cpp └── areaCT.cpp ├── src ├── DC3.cpp ├── DancingLinks.cpp ├── DancingLinks.tex ├── DancingLinks.tex.aux ├── Dominator Tree.cpp ├── Hopcroft.cpp ├── KDTree ├── KDTree.cpp ├── KM ├── KM.cpp ├── LCT.cpp ├── Main.class ├── Main.java ├── NTT.cpp ├── Pell方程.cpp ├── Romberg.cpp ├── Splay.cpp ├── check │ ├── HDU2389Hopcroft.cpp │ ├── POJ2069最小覆盖球.cpp │ ├── POJ2914无向图最小割.cpp │ └── ZOJ3316带花树.cpp ├── draft.py ├── draft.tex ├── fft.cpp ├── list.in ├── table.in ├── tmp.cpp ├── vimrc.vim ├── 三维凸包.cpp ├── 三角形的心.cpp ├── 二次剩余.cpp ├── 二维几何.cpp ├── 二维集合续.cpp ├── 动态最小生成树.cpp ├── 后缀数组(nlogn).cpp ├── 后缀自动机.cpp ├── 启发式分解.cpp ├── 回文串manacher.cpp ├── 图同构Hash.tex ├── 字符串最小表示.cpp ├── 带花树.cpp ├── 弦图相关.tex ├── 无向图最小割.cpp ├── 最大团.cpp ├── 最小覆盖球.cpp ├── 最远点对.cpp ├── 极大团计数.cpp ├── 直线下格点统计.cpp ├── 直线和凸包交点(返回最近和最远点).cpp ├── 积分表.aux ├── 积分表.log ├── 积分表.out ├── 积分表.pdf ├── 积分表.tex ├── 素数判定.cpp ├── 线性规划.cpp ├── 经纬度求球面最短距离.cpp ├── 综合.tex ├── 蔡勒公式.cpp ├── 轻重链剖分.cpp └── 长方体表面两点最短距离.cpp └── tools ├── ISM.TTF └── setuptools-15.2.zip /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | _minted-main/* 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | xelatex -shell-escape main.tex 3 | xelatex -shell-escape main.tex 4 | open main.pdf 5 | clean: 6 | rm main.log main.pdf main.toc main.aux 7 | rm -rf _minted-main 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Dreadnought Code Library for World Finals 2016** 2 | 3 | ## 二维几何 4 | 5 | 二维几何基本操作 6 | 7 | n log n 半平面交 8 | 9 | 三角形的心 10 | 11 | 圆与多边形面积交 12 | 13 | 圆的面积模板 (n^2 log n) 14 | 15 | 凸包快速询问 16 | 17 | Delaunay 三角剖分 18 | 19 | ## 三维几何 20 | 21 | 三维几何基本操作 22 | 23 | 三维凸包求重心 24 | 25 | 求四点外界球 26 | 27 | ## 图论 28 | 29 | Hungarian 30 | 31 | Hopcroft 32 | 33 | 最大团 34 | 35 | 最小树形图 36 | 37 | 带花树 38 | 39 | Dominator Tree 40 | 41 | 主流 42 | 43 | 无向图最小割 44 | 45 | ## 数论 46 | 47 | 素数判定 48 | 49 | 启发式分解 50 | 51 | 直线下整点个数 52 | 53 | 二次剩余 54 | 55 | Pell 方程 56 | 57 | ## 代数 58 | 59 | FFT 60 | 61 | 线性规划 62 | 63 | Schreier-Sims 64 | 65 | ## 字符串 66 | 67 | 后缀数组 ( 倍增 ) 68 | 69 | 后缀自动机 70 | 71 | Manacher/ 扩展 KMP 72 | 73 | 字符串最小表示 74 | 75 | 后缀树 (With Pop Front) 76 | 77 | ## 数据结构 78 | 79 | Splay Tree 80 | 81 | Link Cut Tree 82 | 83 | 轻重链剖分 84 | 85 | ## 综合 86 | 87 | DancingLinks 88 | 89 | 日期公式 90 | 91 | 环状最长公共子序列 92 | 93 | 经纬度球面距离 94 | 95 | 长方体表面两点最短距离 96 | 97 | ## 其他 98 | 99 | 简易积分表 100 | 101 | 常用结论 102 | 103 | Java 读入优化 104 | 105 | Vimrc 106 | 107 | 常用常数表 108 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/Dracarys.zip -------------------------------------------------------------------------------- /SCL-collection/DracarysA/geometry_ex.tex: -------------------------------------------------------------------------------- 1 | get a s->t plane satisfied $ax + by + c \geq 0$ 2 | 3 | return {-1, 0, 1} 4 | \begin{lstlisting} 5 | int getHalfPlane(LD a, LD b, LD c, Point &s, Point &t) 6 | { 7 | if (sign(a)) { 8 | s.y = 0; 9 | s.x = -c / a; 10 | } else if (sign(b)) { 11 | s.x = 0; 12 | s.y = -c / b; 13 | } else { 14 | if (sign(c) < 0) return -1; 15 | return 1; 16 | } 17 | t = s + Point(b, -a); 18 | return 0; 19 | } 20 | \end{lstlisting} 21 | 22 | get a line s-t satisfied $ax + by + c = 0, a^2+b^2\neq 0$ 23 | \begin{lstlisting} 24 | void getLine(LD a, LD b, LD c, Point &s, Point &t) 25 | { 26 | if (sign(a)) { 27 | s.y = 0; 28 | s.x = -c / a; 29 | } else { 30 | s.x = 0; 31 | s.y = -c / b; 32 | } 33 | t = s + Point(b, -a); 34 | } 35 | \end{lstlisting} -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\contentsline {section}{\numberline {1}Simplex Algorithm}{1}} 3 | \@writefile{toc}{\contentsline {section}{\numberline {2}Fast Fourier Transform}{2}} 4 | \@writefile{toc}{\contentsline {section}{\numberline {3}Geometry Extended}{4}} 5 | \@writefile{toc}{\contentsline {section}{\numberline {4}Dominator Tree}{4}} 6 | \@writefile{toc}{\contentsline {section}{\numberline {5}vimrc}{6}} 7 | -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/DracarysA/main.pdf -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/DracarysA/main.synctex.gz -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main.tex: -------------------------------------------------------------------------------- 1 | \documentclass[landscape,a4paper,10pt,twocolumn]{article} 2 | \usepackage{amsmath} 3 | \usepackage{amssymb} 4 | \usepackage{fontspec} 5 | \usepackage{listings} 6 | \usepackage{harpoon} 7 | \usepackage[left=0cm, right=0cm]{geometry} 8 | \usepackage[BoldFont]{xeCJK} 9 | \oddsidemargin -0.1 true cm 10 | \if@twoside 11 | \evensidemargin -0.1 true cm 12 | \fi 13 | \setlength{\parindent}{0em} 14 | \lstset{ 15 | language=C++, 16 | tabsize=2, 17 | breaklines=tr, 18 | extendedchars=false 19 | } 20 | 21 | \title{\Large{Dracarys} \\ [2ex] \LARGE{Standard Code Library} \\[2ex] \begin{normalsize} $\beta$ version \end{normalsize}} 22 | \date{October, 2014} 23 | 24 | \begin{document} 25 | 26 | \maketitle 27 | 28 | \tableofcontents 29 | 30 | \newpage 31 | 32 | \newpage 33 | \section{Simplex Algorithm} 34 | \input{simplex.tex} 35 | 36 | \newpage 37 | \section{Fast Fourier Transform} 38 | \input{ntt.tex} 39 | 40 | \newpage 41 | \section{Geometry Extended} 42 | \input{geometry_ex.tex} 43 | 44 | \newpage 45 | \section{Dominator Tree} 46 | \input{dom.tex} 47 | 48 | \newpage 49 | \section{vimrc} 50 | \input{vimrc.vim} 51 | \end{document} 52 | -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main.toc: -------------------------------------------------------------------------------- 1 | \contentsline {section}{\numberline {1}Simplex Algorithm}{1} 2 | \contentsline {section}{\numberline {2}Fast Fourier Transform}{2} 3 | \contentsline {section}{\numberline {3}Geometry Extended}{4} 4 | \contentsline {section}{\numberline {4}Dominator Tree}{4} 5 | \contentsline {section}{\numberline {5}vimrc}{6} 6 | -------------------------------------------------------------------------------- /SCL-collection/DracarysA/main_bak.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/DracarysA/main_bak.pdf -------------------------------------------------------------------------------- /SCL-collection/DracarysA/ntt.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | 3 | //$P=C*2^k+1$ 4 | //$G$ is primitive root of P 5 | const int N = ; 6 | const int P = 786433; 7 | const int G = 10; 8 | int modPow(long long a, int b, int c) 9 | { 10 | int ret = 1; 11 | for( ; b; b >>= 1) { 12 | if (b & 1) 13 | ret = (long long)ret * a % c; 14 | a = (long long)a * a % c; 15 | } 16 | return ret; 17 | } 18 | void dft(int *x, int on, int n) 19 | { 20 | int k, id, r, tmp, u, t; 21 | for(int i = 1, j = n >> 1; i < n - 1; ++ i) { 22 | if (i < j) swap(x[i], x[j]); 23 | for(k = n >> 1; j >= k; j -= k, k >>= 1); 24 | j += k; 25 | } 26 | for(int h = 2; h <= n; h <<= 1) { 27 | r = modPow(G, (P - 1) / h, P); 28 | if (on < 0) r = modPow(r, P - 2, P); 29 | int p = h >> 1; 30 | for(int j = 0; j < n; j += h) { 31 | int w = 1; 32 | for(int k = j; k < j + p; k ++) { 33 | u = x[k]; 34 | id = k + p; 35 | t = (long long)w * x[id] % P; 36 | x[k] = (u + t) % P; 37 | x[id] = (u - t + P) % P; 38 | w = (long long)w * r % P; 39 | } 40 | } 41 | } 42 | } 43 | int xa[N], xb[N]; 44 | void dft(int *a, int lenA, int *b, int lenB, int *ans, int &lenAns) { 45 | for(lenAns = 1; lenAns < lenA + lenB; lenAns <<= 1); 46 | for(int i = 0; i < lenAns; ++ i) xa[i] = xb[i] = 0; 47 | for(int i = 0; i < lenA; ++ i) xa[i] = a[i] % P; 48 | for(int i = 0; i < lenB; ++ i) xb[i] = b[i] % P; 49 | dft(xa, 1, lenAns); 50 | dft(xb, 1, lenAns); 51 | for(int i = 0; i < lenAns; ++ i) 52 | xa[i] = (long long)xa[i] * xb[i] % P; 53 | dft(xa, -1, lenAns); 54 | int tmp = modPow(lenAns, P - 2, P); 55 | for(int i = 0; i < lenAns; ++ i) 56 | ans[i] = (long long)xa[i]* tmp % P; 57 | } 58 | \end{lstlisting} -------------------------------------------------------------------------------- /SCL-collection/DracarysA/simplex.tex: -------------------------------------------------------------------------------- 1 | $\max\{cx | Ax \leq b, x \geq 0\}$ 2 | if there is no solution or no bound, return a empty vector 3 | \begin{lstlisting} 4 | vector simplex(vector > A, vector b, vector c) 5 | { 6 | int n = A.size(), m = A[0].size() + 1, r = n, s = m - 1; 7 | vector > D(n + 2, vector(m + 1, 0)); 8 | vector ix(n + m); 9 | for (int i = 0; i < n + m; ++ i) ix[i] = i; 10 | for (int i = 0; i < n; ++ i) { 11 | for (int j = 0; j < m - 1; ++ j) D[i][j] = -A[i][j]; 12 | D[i][m - 1] = 1; 13 | D[i][m] = b[i]; 14 | if (D[r][m] > D[i][m]) r = i; 15 | } 16 | for (int j = 0; j < m - 1; ++ j) D[n][j] = c[j]; 17 | D[n + 1][m - 1] = -1; 18 | for (double d; ; ) { 19 | if (r < n) { 20 | int t = ix[s]; ix[s] = ix[r + m]; ix[r + m] = t; 21 | D[r][s] = 1.0 / D[r][s]; 22 | vector speedUp; 23 | for (int j = 0; j <= m; ++ j) if (j != s) { 24 | D[r][j] *= -D[r][s]; 25 | if(D[r][j]) { 26 | speedUp.push_back(j); 27 | } 28 | } 29 | for (int i = 0; i <= n + 1; ++ i) if (i != r) { 30 | for(int j = 0; j < speedUp.size(); ++ j) 31 | D[i][speedUp[j]] += D[r][speedUp[j]] * D[i][s]; 32 | D[i][s] *= D[r][s]; 33 | } 34 | } 35 | r = -1; s = -1; 36 | for (int j = 0; j < m; ++ j) if (s < 0 || ix[s] > ix[j]) { 37 | if (D[n + 1][j] > EPS || (D[n + 1][j] > -EPS && D[n][j] > EPS)) s = j; 38 | } 39 | if (s < 0) break; 40 | for (int i = 0; i < n; ++ i) if (D[i][s] < -EPS) { 41 | if (r < 0 || (d = D[r][m] / D[r][s] - D[i][m] / D[i][s]) < -EPS || (d < EPS && ix[r + m] > ix[i + m])) 42 | r = i; 43 | } 44 | if (r < 0) return vector(); // no bound 45 | } 46 | if (D[n + 1][m] < -EPS) return vector(); // no solution 47 | vector x(m - 1); 48 | for (int i = m; i < n + m; ++ i) if (ix[i] < m - 1) x[ix[i]] = D[i - m][m]; 49 | return x; // max answer is D[n][m] 50 | } 51 | \end{lstlisting} -------------------------------------------------------------------------------- /SCL-collection/DracarysA/tmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/DracarysA/tmp -------------------------------------------------------------------------------- /SCL-collection/DracarysA/tmp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/DracarysA/tmp.cpp -------------------------------------------------------------------------------- /SCL-collection/DracarysA/vimrc.vim: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | set nu ai ci si mouse=a ts=4 sts=4 sw=4 3 | 4 | nmap ggVG 5 | vmap "+y 6 | 7 | nmap : vs %<.in 8 | nmap : !gedit % 9 | nmap : !./%< 10 | nmap : !./%< < %<.in 11 | nmap : make %< 12 | 13 | "nmap :!export CXXFLAGS=-Wall && make %< 14 | "autocmd BufNewFile *.cpp 0r ~/temp.cpp 15 | "set hlsearch incseach 16 | 17 | "syntax on 18 | "filetype plugin indent on 19 | \end{lstlisting} -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/Dracarys_wf.docx -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/Dracarys_wf.zip -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/DC3.cpp: -------------------------------------------------------------------------------- 1 | //DC3 待排序的字符串放在r 数组中,从r[0]到r[n-1],长度为n,且最大值小于m。 2 | //约定除r[n-1]外所有的r[i]都大于0, r[n-1]=0。 3 | //函数结束后,结果放在sa 数组中,从sa[0]到sa[n-1]。 4 | #define maxn 10000 5 | #define F(x) ((x)/3+((x)%3==1?0:tb)) 6 | #define G(x) ((x)=0;i--) b[--wss[wv[i]]]=a[i]; 19 | } 20 | void dc3(int *r,int *sa,int n,int m){ 21 | int i,j,*rn=r+n,*san=sa+n,ta=0,tb=(n+1)/3,tbc=0,p; 22 | r[n]=r[n+1]=0; 23 | for(i=0;idx[i]) 37 | dx[i]=a[i][j]; 38 | } 39 | for (int i=1;i<=n;i++) 40 | { 41 | memset(slack,63,sizeof(slack)); 42 | memset(f,0,sizeof(f)); 43 | memset(g,0,sizeof(g)); 44 | while (!hungary(i)) 45 | { 46 | int d=inf; 47 | for (int i=1;i<=n;i++) 48 | if (!g[i] && slack[i]>= 1) { 9 | if (b & 1) 10 | ret = (long long)ret * a % c; 11 | a = (long long)a * a % c; 12 | } 13 | return ret; 14 | } 15 | void dft(int *x, int on, int n) 16 | { 17 | int k, id, r, tmp, u, t; 18 | for(int i = 1, j = n >> 1; i < n - 1; ++ i) { 19 | if (i < j) swap(x[i], x[j]); 20 | for(k = n >> 1; j >= k; j -= k, k >>= 1); 21 | j += k; 22 | } 23 | for(int h = 2; h <= n; h <<= 1) { 24 | r = modPow(G, (P - 1) / h, P); 25 | if (on < 0) r = modPow(r, P - 2, P); 26 | int p = h >> 1; 27 | for(int j = 0; j < n; j += h) { 28 | int w = 1; 29 | for(int k = j; k < j + p; k ++) { 30 | u = x[k]; 31 | id = k + p; 32 | t = (long long)w * x[id] % P; 33 | x[k] = (u + t) % P; 34 | x[id] = (u - t + P) % P; 35 | w = (long long)w * r % P; 36 | } 37 | } 38 | } 39 | } 40 | int xa[N], xb[N]; 41 | 42 | void dft(int *a, int lenA, int *b, int lenB, int *ans, int &lenAns) 43 | { 44 | for(lenAns = 1; lenAns < lenA + lenB; lenAns <<= 1); 45 | for(int i = 0; i < lenAns; ++ i) { 46 | xa[i] = xb[i] = 0; 47 | } 48 | for(int i = 0; i < lenA; ++ i) { 49 | xa[i] = a[i] % P; 50 | } 51 | for(int i = 0; i < lenB; ++ i) { 52 | xb[i] = b[i] % P; 53 | } 54 | 55 | dft(xa, 1, lenAns); 56 | dft(xb, 1, lenAns); 57 | for(int i = 0; i < lenAns; ++ i) { 58 | xa[i] = (long long)xa[i] * xb[i] % P; 59 | } 60 | dft(xa, -1, lenAns); 61 | int tmp = modPow(lenAns, P - 2, P); 62 | for(int i = 0; i < lenAns; ++ i) { 63 | ans[i] = (long long)xa[i]* tmp % P; 64 | } 65 | } -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/Pell方程.cpp: -------------------------------------------------------------------------------- 1 | ULL A,B,p[maxn],q[maxn],a[maxn],g[maxn],h[maxn]; 2 | int main() 3 | { 4 | int n; 5 | for (int test=1;scanf("%d",&n) && n;++test) 6 | { 7 | printf("Case %d: ",test); 8 | if (fabs(sqrt(n)-floor(sqrt(n)+1e-7))<=1e-7) 9 | { 10 | int a=(int)(floor(sqrt(n)+1e-7)); 11 | printf("%d %d\n",a,1); 12 | }else 13 | { 14 | //求x^2-ny^2=1的最小正整数根,n不是完全平方数 15 | p[1]=1;p[0]=0; 16 | q[1]=0;q[0]=1; 17 | a[2]=(int)(floor(sqrt(n)+1e-7)); 18 | g[1]=0;h[1]=1; 19 | for (int i=2;i;++i) 20 | { 21 | g[i]=-g[i-1]+a[i]*h[i-1]; 22 | h[i]=(n-sqr(g[i]))/h[i-1]; 23 | a[i+1]=(g[i]+a[2])/h[i]; 24 | p[i]=a[i]*p[i-1]+p[i-2]; 25 | q[i]=a[i]*q[i-1]+q[i-2]; 26 | if (sqr((ULL)(p[i]))-n*sqr((ULL)(q[i]))==1) 27 | { 28 | A=p[i];B=q[i]; 29 | break; 30 | } 31 | } 32 | cout << A << ' ' << B < 2 | double romberg(const T&f,double a,double b,double eps=1e-8){ 3 | std::vectort; 4 | double h=b-a,last,curr; 5 | int k=1,i=1; 6 | t.push_back(h*(f(a)+f(b))/2); // 梯形 7 | do{ 8 | last=t.back(); 9 | curr=0; 10 | double x=a+h/2; 11 | for(int j=0;jeps); 30 | return t.back(); 31 | } 32 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/三维凸包求重心.cpp: -------------------------------------------------------------------------------- 1 | double calcDist(const Point &p, int a, int b, int c) { 2 | return fabs(mix(info[a] - p, info[b] - p, info[c] - p) / area(a, b, c)); 3 | } 4 | //compute the minimal distance of center of any faces 5 | double findDist() { 6 | //compute center of mass 7 | double totalWeight = 0; 8 | Point center(.0, .0, .0); 9 | Point first = info[face[0][0]]; 10 | for (int i = 0; i < SIZE(face); ++i) { 11 | Point p = (info[face[i][0]] + info[face[i][1]] + info[face[i][2]] + first) * .25; 12 | double weight = mix(info[face[i][0]] - first, info[face[i][1]] - first, info[face[i][2]] - first); 13 | totalWeight += weight; 14 | center = center + p * weight; 15 | } 16 | center = center / totalWeight; 17 | //compute distance 18 | double res = 1e100; 19 | for (int i = 0; i < SIZE(face); ++i) { 20 | res = min(res, calcDist(center, face[i][0], face[i][1], face[i][2])); 21 | } 22 | return res; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/三维旋转操作.cpp: -------------------------------------------------------------------------------- 1 | //a点绕Ob向量,逆时针旋转弧度angle, sin(angle),cos(angle)先求出来,减少精度问题。 2 | point e1,e2,e3; point Rotate( point a, point b, double angle ){ 3 | b.std();//单位化,注意b不能为(0,0,0) 4 | e3=b; double lens=a*e3;//dot(a,e3) 5 | e1=a - e3*lens; if (e1.len()>(1e-8)) e1.std(); else return a; 6 | e2=e1/e3; //det(e1,e3) 7 | double x1,y1,x,y; y1=a*e1; x1=a*e2; 8 | x=x1*cos(angle) - y1*sin(angle); y=x1*sin(angle) + y1*cos(angle); 9 | return e3*lens + e1*y + e2*x; } 10 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/三角形的心.cpp: -------------------------------------------------------------------------------- 1 | //传入的参数point a,b,c; 三角形顶点 2 | double area(point a,point b,point c) //面积 3 | { 4 | return(fabs(det(b-a,c-a))/2); 5 | } 6 | point barycenter(point a,point b,point c) //重心 7 | { 8 | return(point((a.x+b.x+c.x)/3.0,(a.y+b.y+c.y)/3.0)); 9 | } 10 | point orthocenter(point a,point b,point c) //垂心 11 | { 12 | double d,dx,dy; 13 | d=(c.x-b.x)*(c.y-a.y)-(c.x-a.x)*(c.y-b.y); 14 | dx=(a.y*(c.y-b.y)+a.x*(c.x-b.x))*(c.y-a.y)-(b.y*(c.y-a.y)+b.x*(c.x-a.x))*(c.y-b.y); 15 | dy=(c.x-b.x)*(b.y*(c.y-a.y)+b.x*(c.x-a.x))-(c.x-a.x)*(a.y*(c.y-b.y)+a.x*(c.x-b.x)); 16 | return(point(dx/d,dy/d)); 17 | } 18 | point circumcenter(point a,point b,point c) //外心 19 | { 20 | double A,B,C; 21 | A=dist(b,c),B=dist(a,c),C=dist(a,b); 22 | double P,Q; 23 | P=(SQR(A)+SQR(B)+SQR(C))/2.0; 24 | Q=1.0/(1/(P-SQR(A))+1/(P-SQR(B))+1/(P-SQR(C))); 25 | double R=sqrt(P-Q)/2; //R为外接圆半径,需要时可用,否则可删去 26 | double d1,d2,d3; 27 | d1=Q/(P-SQR(A)),d2=Q/(P-SQR(B)),d3=Q/(P-SQR(C)); 28 | return((1-d1)/2.0*a+(1-d2)/2.0*b+(1-d3)/2.0*c); 29 | } 30 | point incenter(point a,point b,point c) 31 | { 32 | double A,B,C; 33 | A=dist(b,c),B=dist(a,c),C=dist(a,b); 34 | double r=2*area(a,b,c)/(A+B+C); //r为内切圆半径,需要时可用 ,否则可删去 35 | return(point((A*a.x+B*b.x+C*c.x)/(A+B+C),(A*a.y+B*b.y+C*c.y)/(A+B+C))); 36 | } 37 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/二次剩余.cpp: -------------------------------------------------------------------------------- 1 | int power(int a, int b, const int MODE) { 2 | if (b == 0) return 1; 3 | int t = power(a, b / 2, MODE); 4 | t = (t * t) % MODE; 5 | if (b & 1) t = (t * a) % MODE; 6 | return t; 7 | } 8 | void calcH(int &t, int &h, const int p) { 9 | int tmp = p - 1; 10 | for (t = 0; (tmp & 1) == 0; tmp /= 2) t++; 11 | h = tmp; 12 | } 13 | // solve equation x^2 mod p = a 14 | bool solve(int a, int p, int &x, int &y) { 15 | srand(19920225); 16 | if (p == 2) { 17 | x = y = 1; 18 | return true; 19 | } 20 | int p2 = p / 2; 21 | int tmp = power(a, p2, p); 22 | if (tmp == p - 1) return false; 23 | if ((p + 1) % 4 == 0) { 24 | x = power(a, (p + 1) / 4, p); 25 | y = p - x; 26 | return true; 27 | } else { 28 | int t, h, b, pb; 29 | calcH(t, h, p); 30 | if (t >= 2) { 31 | do { 32 | b = rand() % (p - 2) + 2; 33 | } 34 | while (power(b, p / 2, p) != p - 1); 35 | pb = power(b, h, p); 36 | } 37 | int s = power(a, h / 2, p); 38 | for (int step = 2; step <= t; step++) { 39 | int ss = (((s * s) % p) * a) % p; 40 | for (int i = 0; i < t - step; i++) ss = (ss * ss) % p; 41 | if (ss + 1 == p) s = (s * pb) % p; 42 | pb = (pb * pb) % p; 43 | } 44 | x = (s * a) % p; 45 | y = p - x; 46 | } 47 | return true; 48 | } 49 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/动态树.cpp: -------------------------------------------------------------------------------- 1 | struct Node 2 | { 3 | Node *ch[2], *p; 4 | int isroot; 5 | bool dir(); 6 | void set(Node*, bool); 7 | void update(); 8 | void relax(); 9 | } *null; 10 | void rot(Node *t) 11 | { 12 | Node *p = t->p; bool d = t->dir(); 13 | p->relax(); t->relax(); 14 | p->set(t->ch[! d], d); 15 | if (p->isroot) t->p = p->p, swap(p->isroot, t->isroot); 16 | else p->p->set(t, p->dir()); 17 | t->set(p, ! d); 18 | p->update(); 19 | } 20 | void Splay(Node *t) 21 | { 22 | for(t->relax(); ! t->isroot; ) { 23 | if (t->p->isroot) rot(t); 24 | else t->dir() == t->p->dir() ? (rot(t->p), rot(t)) : (rot(t), rot(t)); 25 | } 26 | t->update(); 27 | } 28 | void Access(Node *t) 29 | { 30 | for(Node *s = null; t != null; s = t, t = t->p) { 31 | Splay(t); 32 | t->ch[1]->isroot = true; 33 | s->isroot = false; 34 | t->ch[1] = s; 35 | t->update(); 36 | } 37 | } 38 | bool Node::dir() { 39 | return this == p->ch[1]; 40 | } 41 | void Node::set(Node *t, bool _d) { 42 | ch[_d] = t; t->p = this; 43 | } 44 | void Node::Update(){ 45 | } 46 | void Node::Relax(){ 47 | if (this == Null) return; 48 | } -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/后缀数组(nlogn).cpp: -------------------------------------------------------------------------------- 1 | const int MAX_N = 1000000 + 10; 2 | int rank[MAX_N], height[MAX_N]; 3 | int cmp(int *x, int a, int b, int d) { 4 | return x[a] == x[b] && x[a + d] == x[b + d]; 5 | } 6 | 7 | void doubling(int *a, int N, int M) { 8 | static int sRank[MAX_N], tmpA[MAX_N], tmpB[MAX_N]; 9 | int *x = tmpA, *y = tmpB; 10 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 11 | for(int i = 0; i < N; ++ i) ++ sRank[x[i] = a[i]]; 12 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 13 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[i]]] = i; 14 | 15 | for(int d = 1, p = 0; p < N; M = p, d <<= 1) { 16 | p = 0; for(int i = N - d; i < N; ++ i) y[p ++] = i; 17 | for(int i = 0; i < N; ++ i) 18 | if (sa[i] >= d) y[p ++] = sa[i] - d; 19 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 20 | for(int i = 0; i < N; ++ i) ++ sRank[x[i]]; 21 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 22 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[y[i]]]] = y[i]; 23 | swap(x, y); x[sa[0]] = 0; p = 1; 24 | for(int i = 1; i < N; ++ i) 25 | x[sa[i]] = cmp(y, sa[i], sa[i - 1], d) ? p - 1 : p ++; 26 | } 27 | } 28 | 29 | void calcHeight() { 30 | for(int i = 0; i < N; ++ i) rank[sa[i]] = i; 31 | int cur = 0; 32 | for(int i = 0; i < N; ++ i) 33 | if (rank[i]) { 34 | if (cur) cur --; 35 | for( ; a[i + cur] == a[sa[rank[i] - 1] + cur]; ++ cur); 36 | height[rank[i]] = cur; 37 | } 38 | } -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/后缀自动机.cpp: -------------------------------------------------------------------------------- 1 | struct State { 2 | int length; 3 | State *parent; 4 | State *go[C]; 5 | State(int length): length(length), parent(NULL) { 6 | memset(go, 0, sizeof(go)); 7 | } 8 | State* extend(State *start, int token) { 9 | State *p = this; 10 | State *np = new State(this->length + 1); 11 | while (p != NULL && p->go[token] == NULL) { 12 | p->go[token] = np; 13 | p = p->parent; 14 | } 15 | if (p == NULL) { 16 | np->parent = start; 17 | } else { 18 | State *q = p->go[token]; 19 | if (p->length + 1 == q->length) { 20 | np->parent = q; 21 | } else { 22 | State *nq = new State(p->length + 1); 23 | memcpy(nq->go, q->go, sizeof(q->go)); 24 | nq->parent = q->parent; 25 | np->parent = q->parent = nq; 26 | while (p != NULL && p->go[token] == q) { 27 | p->go[token] = nq; 28 | p = p->parent; 29 | } 30 | } 31 | } 32 | return np; 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/回文串manacher.cpp: -------------------------------------------------------------------------------- 1 | for(int i = 1, j = 0; i != (n << 1)- 1; ++ i) 2 | { 3 | int p = i >> 1, q = i - p, r = ((j + 1) >> 1) + l[j] - 1; 4 | l[i] = r < q? 0: min(r - q + 1, l[(j << 1) - i]); 5 | while(p - l[i] != -1 && q + l[i] != n && s[p - l[i]] == s[q + l[i]]) 6 | l[i] ++; 7 | if(q + l[i] - 1 > r) j = i; 8 | a += l[i]; 9 | } 10 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/多边形与圆面积交.cpp: -------------------------------------------------------------------------------- 1 | point ORI; 2 | double r; 3 | int n; 4 | point info[maxn]; 5 | //用有向面积,划分成一个三角形和圆的面积的交 6 | double area2(point pa, point pb) { 7 | if (pa.len() < pb.len()) swap(pa, pb); 8 | if (pb.len() < eps) return 0; 9 | double a, b, c, B, C, sinB, cosB, sinC, cosC, S, h, theta; 10 | a = pb.len(); 11 | b = pa.len(); 12 | c = (pb - pa).len(); 13 | cosB = dot(pb, pb - pa) / a / c; 14 | B = acos(cosB); 15 | cosC = dot(pa, pb) / a / b; 16 | C = acos(cosC); 17 | if (a > r) { 18 | S = (C/2)*r*r; 19 | h = a*b*sin(C)/c; 20 | if (h < r && B < PI/2) S -= (acos(h/r)*r*r - h*sqrt(r*r-h*h)); 21 | } else if (b > r) { 22 | theta = PI - B - asin(sin(B)/r*a); 23 | S = .5*a*r*sin(theta) + (C-theta)/2*r*r; 24 | } else { 25 | S = .5*sin(C)*a*b; 26 | } 27 | //printf("res = %.4f\n", S); 28 | return S; 29 | } 30 | double area() { 31 | double S = 0; 32 | for (int i = 0; i < n; ++i) { 33 | S += area2(info[i], info[i + 1]) * Sign(cross(info[i], info[i + 1])); 34 | } 35 | return fabs(S); 36 | } 37 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/字符串最小表示.cpp: -------------------------------------------------------------------------------- 1 | std::string find(std::string s) { 2 | int i, j, k, l; 3 | int N = s.length(); 4 | s += s; 5 | for (i = 0, j = 1; j < N; ) { 6 | for (k = 0; k < N && s[i + k] == s[j + k]; k ++); 7 | if (k >= N) break; 8 | if (s[i + k] < s[j + k]) { 9 | j += k + 1; 10 | } else { 11 | l = i + k; 12 | i = j; 13 | j = max(l, j) + 1; 14 | } 15 | } 16 | return s.substr(i, N); 17 | } 18 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/无向图最小割.cpp: -------------------------------------------------------------------------------- 1 | int cost[maxn][maxn], seq[maxn], len[maxn], n, m, pop, ans; 2 | bool used[maxn]; 3 | void Init() { 4 | int i, j, a, b, c; 5 | for (i = 0; i < n; i++) 6 | for (j = 0; j < n; j++) 7 | cost[i][j] = 0; 8 | for (i = 0; i < m; i++) { 9 | scanf("%d %d %d", &a, &b, &c); 10 | cost[a][b] += c; 11 | cost[b][a] += c; 12 | } 13 | pop = n; 14 | for (i = 0; i < n; i++) 15 | seq[i] = i; 16 | } 17 | void Work() { 18 | ans = inf; 19 | int i, j, k, l, mm, sum, pk; 20 | while (pop > 1) { 21 | for (i = 1; i < pop; i++) 22 | used[seq[i]] = 0; 23 | used[seq[0]] = 1; 24 | for (i = 1; i < pop; i++) 25 | len[seq[i]] = cost[seq[0]][seq[i]]; 26 | pk = 0; 27 | mm = -inf; 28 | k = -1; 29 | for (i = 1; i < pop; i++) 30 | if (len[seq[i]] > mm) { 31 | mm = len[seq[i]]; 32 | k = i; 33 | } 34 | for (i = 1; i < pop; i++) { 35 | used[seq[l = k]] = 1; 36 | if (i == pop - 2) pk = k; 37 | if (i == pop - 1) break; 38 | mm = -inf; 39 | for (j = 1; j < pop; j++) 40 | if (!used[seq[j]]) { 41 | if ((len[seq[j]] += cost[seq[l]][seq[j]]) > mm) { 42 | mm = len[seq[j]]; 43 | k = j; 44 | }; 45 | } 46 | } 47 | sum = 0; 48 | for (i = 0; i < pop; i++) 49 | if (i != k) sum += cost[seq[k]][seq[i]]; 50 | ans = min(ans, sum); 51 | for (i = 0; i < pop; i++) 52 | cost[seq[k]][seq[i]] = cost[seq[i]][seq[k]] += cost[seq[pk]][seq[i]]; 53 | seq[pk] = seq[--pop]; 54 | } 55 | printf("%d\n", ans); 56 | } 57 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/最大团.cpp: -------------------------------------------------------------------------------- 1 | Int g[][]为图的邻接矩阵。 2 | MC(V)表示点集V的最大团 3 | 令Si={vi, vi+1, ..., vn}, mc[i]表示MC(Si) 4 | 倒着算mc[i],那么显然MC(V)=mc[1] 5 | 此外有mc[i]=mc[i+1] or mc[i]=mc[i+1]+1 6 | void init(){ 7 | int i, j; 8 | for (i=1; i<=n; ++i) for (j=1; j<=n; ++j) scanf("%d", &g[i][j]); 9 | } 10 | void dfs(int size){ 11 | int i, j, k; 12 | if (len[size]==0) { 13 | if (size>ans) { 14 | ans=size; found=true; 15 | } 16 | return; 17 | } 18 | for (k=0; k1 && (conv[totco-1]-conv[totco-2])/(p[i]-conv[totco-2])<=0 ) totco--; 9 | conv[totco++]=p[i]; 10 | } 11 | int limit=totco; 12 | for ( int i=n-1; i>=0; i-- ){ 13 | while ( totco>limit && (conv[totco-1]-conv[totco-2])/(p[i]-conv[totco-2])<=0 ) totco--; 14 | conv[totco++]=p[i]; 15 | } 16 | } 17 | point pp[100000]; 18 | int main(){ 19 | scanf("%d", &n); 20 | for ( int i=0; i0 ) now++; 33 | if ( dist( pp[i], pp[now] )>ans ) ans=dist( pp[i], pp[now] ); 34 | if ( dist( pp[i+1], pp[now] )>ans ) ans=dist( pp[i+1], pp[now] ); 35 | } 36 | printf("%d\n", ans); 37 | } 38 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/极大团计数.cpp: -------------------------------------------------------------------------------- 1 | Bool g[][] 为图的邻接矩阵,图点的标号由1至n。 2 | void dfs(int size){ 3 | int i, j, k, t, cnt, best = 0; 4 | bool bb; 5 | if (ne[size]==ce[size]){ 6 | if (ce[size]==0) ++ans; 7 | return; 8 | } 9 | for (t=0, i=1; i<=ne[size]; ++i) { 10 | for (cnt=0, j=ne[size]+1; j<=ce[size]; ++j) 11 | if (!g[list[size][i]][list[size][j]]) ++cnt; 12 | if (t==0 || cnt0){ 17 | for (i=k; i<=ce[size]; ++i) if (!g[list[size][t]][list[size][i]]) break; 18 | swap(list[size][k], list[size][i]); 19 | } 20 | i=list[size][k]; 21 | ne[size+1]=ce[size+1]=0; 22 | for (j=1; j simplex(vector > A, vector b, vector c) 2 | { 3 | int n = A.size(), m = A[0].size() + 1, r = n, s = m - 1; 4 | vector > D(n + 2, vector(m + 1, 0)); 5 | vector ix(n + m); 6 | for (int i = 0; i < n + m; ++ i) ix[i] = i; 7 | for (int i = 0; i < n; ++ i) { 8 | for (int j = 0; j < m - 1; ++ j) D[i][j] = -A[i][j]; 9 | D[i][m - 1] = 1; 10 | D[i][m] = b[i]; 11 | if (D[r][m] > D[i][m]) r = i; 12 | } 13 | for (int j = 0; j < m - 1; ++ j) D[n][j] = c[j]; 14 | D[n + 1][m - 1] = -1; 15 | for (double d; ; ) { 16 | if (r < n) { 17 | int t = ix[s]; ix[s] = ix[r + m]; ix[r + m] = t; 18 | D[r][s] = 1.0 / D[r][s]; 19 | vector speedUp; 20 | for (int j = 0; j <= m; ++ j) if (j != s) { 21 | D[r][j] *= -D[r][s]; 22 | if(D[r][j]) { 23 | speedUp.push_back(j); 24 | } 25 | } 26 | for (int i = 0; i <= n + 1; ++ i) if (i != r) { 27 | for(int j = 0; j < speedUp.size(); ++ j) 28 | D[i][speedUp[j]] += D[r][speedUp[j]] * D[i][s]; 29 | D[i][s] *= D[r][s]; 30 | } 31 | } 32 | r = -1; s = -1; 33 | for (int j = 0; j < m; ++ j) if (s < 0 || ix[s] > ix[j]) { 34 | if (D[n + 1][j] > EPS || (D[n + 1][j] > -EPS && D[n][j] > EPS)) s = j; 35 | } 36 | if (s < 0) break; 37 | for (int i = 0; i < n; ++ i) if (D[i][s] < -EPS) { 38 | if (r < 0 || (d = D[r][m] / D[r][s] - D[i][m] / D[i][s]) < -EPS || (d < EPS && ix[r + m] > ix[i + m])) 39 | r = i; 40 | } 41 | if (r < 0) return vector(); // no bound 42 | } 43 | if (D[n + 1][m] < -EPS) return vector(); // no solution 44 | vector x(m - 1); 45 | for (int i = m; i < n + m; ++ i) if (ix[i] < m - 1) x[ix[i]] = D[i - m][m]; 46 | return x; // max answer is D[n][m] 47 | } -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/经纬度求球面最短距离.cpp: -------------------------------------------------------------------------------- 1 | //lati 为纬度 longi为经度 R为半径 2 | double Dist(double lati1,double longi1,double lati2,double longi2,double R) 3 | { 4 | double pi=acos(-1.0); 5 | lati1*=pi/180,longi1*=pi/180,lati2*=pi/180,longi2*=pi/180; 6 | double x1=cos(lati1)*sin(longi1),y1=cos(lati1)*cos(longi1),z1=sin(lati1); 7 | double x2=cos(lati2)*sin(longi2),y2=cos(lati2)*cos(longi2),z2=sin(lati2); 8 | double theta=acos(x1*x2+y1*y2+z1*z2); 9 | return(R*theta); 10 | } 11 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/蔡勒公式.cpp: -------------------------------------------------------------------------------- 1 | int zeller(int y,int m,int d) { 2 | if (m<=2) y--,m+=12; 3 | int c=y/100; 4 | y%=100; 5 | int w=((c>>2)-(c<<1)+y+(y>>2)+(13*(m+1)/5)+d-1)%7; 6 | if (w<0) w+=7; 7 | return(w); 8 | } 9 | -------------------------------------------------------------------------------- /SCL-collection/Dracarys_wf/长方体表面两点最短距离.cpp: -------------------------------------------------------------------------------- 1 | int r; 2 | void turn(int i, int j, int x, int y, int z,int x0, int y0, int L, int W, int H) { 3 | if (z==0) { 4 | int R = x*x+y*y; 5 | if (R=0 && i< 2) 9 | turn(i+1, j, x0+L+z, y, x0+L-x, x0+L, y0, H, W, L); 10 | if(j>=0 && j< 2) 11 | turn(i, j+1, x, y0+W+z, y0+W-y, x0, y0+W, L, H, W); 12 | if(i<=0 && i>-2) 13 | turn(i-1, j, x0-z, y, x-x0, x0-H, y0, H, W, L); 14 | if(j<=0 && j>-2) 15 | turn(i, j-1, x, y0-z, y-y0, x0, y0-H, L, H, W); 16 | } 17 | } 18 | int main(){ 19 | int L, H, W, x1, y1, z1, x2, y2, z2; 20 | cin >> L >> W >> H >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 21 | if (z1!=0 && z1!=H) 22 | if (y1==0 || y1==W) 23 | swap(y1,z1), std::swap(y2,z2), std::swap(W,H); 24 | else 25 | swap(x1,z1), std::swap(x2,z2), std::swap(L,H); 26 | if (z1==H) z1=0, z2=H-z2; 27 | r=0x3fffffff; turn(0,0,x2-x1,y2-y1,z2,-x1,-y1,L,W,H); 28 | cout< s; 20 | if (tmp == b) { 21 | return 0; 22 | } 23 | for (int i = 1; i <= 50; ++ i) { 24 | tmp = ((long long)tmp * a) % m; 25 | if (tmp == b) { 26 | return i; 27 | } 28 | } 29 | int x_0 = 0, d = 1 % m; 30 | while (true) { 31 | tmp = gcd(a, m); 32 | if (tmp == 1) { 33 | break; 34 | } 35 | x_0 ++; 36 | d = ((long long)d * (a / tmp)) % m; 37 | if (b % tmp) { 38 | return -1; 39 | } 40 | b /= tmp; 41 | m /= tmp; 42 | } 43 | b = ((long long)b * inverse(d, m)) % m; 44 | c = int(ceil(sqrt(m))); 45 | s.clear(); 46 | tmp = b; 47 | int tmpInv = intverse(a, m); 48 | for (int i = 0; i != c; ++ i) { 49 | if (s.find(tmp) == s.end()) { 50 | s[tmp] = i; 51 | } 52 | tmp = ((long long)tmp * tmpInv) % m; 53 | } 54 | tmp = 1; 55 | for (int i = 0; i != c; ++ i) { 56 | tmp = ((long long)tmp * a) % m; 57 | } 58 | int ans = 1; 59 | for (int i = 0; i != c; ++ i) { 60 | if (s.find(ans) != s.end()) { 61 | return x_0 + i * c + s.find(ans)->second; 62 | } 63 | ans = ((long long)ans * tmp) % m; 64 | } 65 | return -1; 66 | } 67 | \end{lstlisting} 68 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/GY's lib/SCL_KMP.cpp: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector KMP() 3 | { 4 | vector ans; 5 | nxt[0] = -1; 6 | nxt[1] = 0; 7 | for(int i = 2; i <= m; i++) 8 | { 9 | nxt[i] = nxt[i - 1]; 10 | while(nxt[i] >= 0 and st[i] != st[nxt[i] + 1]) 11 | nxt[i] = nxt[nxt[i]]; 12 | nxt[i]++; 13 | } 14 | for(int i = 1, p = 1; i <= n; i++) 15 | { 16 | while(p and str1[i] != st[p]) 17 | p = nxt[p - 1] + 1; 18 | p++; 19 | if(p == m + 1) p = nxt[m] + 1, ans.push_back(i - m); 20 | } 21 | return ans; 22 | } 23 | \end{lstlisting} 24 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/GY's lib/SCL_KMP.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector KMP() 3 | { 4 | vector ans; 5 | nxt[0] = -1; 6 | nxt[1] = 0; 7 | for(int i = 2; i <= m; i++) 8 | { 9 | nxt[i] = nxt[i - 1]; 10 | while(nxt[i] >= 0 and st[i] != st[nxt[i] + 1]) 11 | nxt[i] = nxt[nxt[i]]; 12 | nxt[i]++; 13 | } 14 | for(int i = 1, p = 1; i <= n; i++) 15 | { 16 | while(p and str1[i] != st[p]) 17 | p = nxt[p - 1] + 1; 18 | p++; 19 | if(p == m + 1) p = nxt[m] + 1, ans.push_back(i - m); 20 | } 21 | return ans; 22 | } 23 | \end{lstlisting} 24 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/GY's lib/SCL_intersect_circle_polygon.cpp~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/GY's lib/SCL_intersect_circle_polygon.cpp~ -------------------------------------------------------------------------------- /SCL-collection/SuperNova/GY's lib/SCL_str_cyc_min_rep.cpp: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct cyc_string 3 | { 4 | int n, offset; 5 | char str[max_length]; 6 | char & operator [] (int x) 7 | {return str[((offset + x) % n)];} 8 | cyc_string(){offset = 0;} 9 | }; 10 | void minimum_circular_representation(cyc_string & a) 11 | { 12 | int i = 0, j = 1, dlt = 0, n = a.n; 13 | while(i < n and j < n and dlt < n) 14 | { 15 | if(a[i + dlt] == a[j + dlt]) dlt++; 16 | else 17 | { 18 | if(a[i + dlt] > a[j + dlt]) i += dlt + 1; else j += dlt + 1; 19 | dlt = 0; 20 | } 21 | } 22 | a.offset = min(i, j); 23 | } 24 | int main() 25 | {return 0;} 26 | \end{lstlisting} 27 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/GY's lib/SCL_str_cyc_min_rep.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct cyc_string 3 | { 4 | int n, offset; 5 | char str[max_length]; 6 | char & operator [] (int x) 7 | {return str[((offset + x) % n)];} 8 | cyc_string(){offset = 0;} 9 | }; 10 | void minimum_circular_representation(cyc_string & a) 11 | { 12 | int i = 0, j = 1, dlt = 0, n = a.n; 13 | while(i < n and j < n and dlt < n) 14 | { 15 | if(a[i + dlt] == a[j + dlt]) dlt++; 16 | else 17 | { 18 | if(a[i + dlt] > a[j + dlt]) i += dlt + 1; else j += dlt + 1; 19 | dlt = 0; 20 | } 21 | } 22 | a.offset = min(i, j); 23 | } 24 | int main() 25 | {return 0;} 26 | \end{lstlisting} 27 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Geo-convexhull.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector convexHull(vector ps) { 3 | int n = ps.size(); 4 | if (n <= 1) 5 | return ps; 6 | sort(ps.begin(), ps.end()); 7 | vector qs; 8 | for (int i = 0; i < n; qs.push_back(ps[i++])) { 9 | while (qs.size() > 1 && crossOp(qs[qs.size()-2],qs.back(),ps[i]) <= 0) 10 | qs.pop_back(); 11 | } 12 | for (int i = n - 2, t = qs.size(); i >= 0; qs.push_back(ps[i--])) { 13 | while (qs.size() > t && crossOp(qs[qs.size()-2],qs.back(),ps[i]) <= 0) 14 | qs.pop_back(); 15 | } 16 | qs.pop_back(); 17 | return qs; 18 | } 19 | \end{lstlisting} 20 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Geo-diameter.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | double convexDiameter(const vector&ps) { 3 | int n = ps.size(); 4 | int is = 0, js = 0; 5 | for (int i = 1; i < n; ++i) { 6 | if (ps[i].x > ps[is].x) 7 | is = i; 8 | if (ps[i].x < ps[js].x) 9 | js = i; 10 | } 11 | double maxd = ps[is].distTo(ps[js]); 12 | int i = is, j = js; 13 | do { 14 | if ((ps[(i + 1) % n] - ps[i]).det(ps[(j + 1) % n] - ps[j]) >= 0) 15 | (++j) %= n; 16 | else 17 | (++i) %= n; 18 | maxd = max(maxd, ps[i].distTo(ps[j])); 19 | } while (i != is || j != js); 20 | return maxd; 21 | } 22 | \end{lstlisting} 23 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Geo/basic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/Geo/basic -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Hopcroft.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | #include 3 | #include 4 | #define maxn 50005 5 | #define maxm 150005 6 | int cx[maxn],cy[maxn],mk[maxn],q[maxn],src[maxn],pre[maxn]; 7 | int head[maxn],vtx[maxm],next[maxm],tot,n,m; 8 | inline void Add(int a,int b) 9 | { 10 | vtx[tot]=b; 11 | next[tot]=head[a]; 12 | head[a]=tot++; 13 | } 14 | inline int Maxmatch() 15 | { 16 | memset(mk,-1,sizeof(mk)); 17 | memset(cx,-1,sizeof(cx)); 18 | memset(cy,-1,sizeof(cy)); 19 | for (int p=1,fl=1,h,tail;fl;++p) 20 | { 21 | fl=0; 22 | h=tail=0; 23 | for (int i=0;i=0) 36 | { 37 | pre[cy[v]]=u; 38 | src[cy[v]]=src[u]; 39 | continue; 40 | } 41 | int d,e,t; 42 | for 43 | (--tail,fl=1,d=u,e=v;d!=-1;t=cx[d],cx[d]=e,cy[e]=d,e=t,d=pre[d]); 44 | break; 45 | } 46 | } 47 | } 48 | int res=0; 49 | for (int i=0;ip; bool d = t->dir(); 15 | p->relax(); t->relax(); 16 | p->set(t->ch[! d], d); 17 | if (p->isroot) t->p = p->p, swap(p->isroot, t->isroot); 18 | else p->p->set(t, p->dir()); 19 | t->set(p, ! d); 20 | p->update(); 21 | } 22 | 23 | void Splay(Node *t) 24 | { 25 | for(t->relax(); ! t->isroot; ) { 26 | if (t->p->isroot) rot(t); 27 | else t->dir() == t->p->dir() ? (rot(t->p), rot(t)) : (rot(t), rot(t)); 28 | } 29 | t->update(); 30 | } 31 | 32 | void Access(Node *t) 33 | { 34 | for(Node *s = null; t != null; s = t, t = t->p) { 35 | Splay(t); 36 | t->ch[1]->isroot = true; 37 | s->isroot = false; 38 | t->ch[1] = s; 39 | t->update(); 40 | } 41 | } 42 | bool Node::dir() 43 | { 44 | return this == p->ch[1]; 45 | } 46 | void Node::set(Node *t, bool _d) 47 | { 48 | ch[_d] = t; t->p = this; 49 | } 50 | void Node::Update() 51 | { 52 | 53 | } 54 | void Node::Relax() 55 | { 56 | if (this == Null) return; 57 | 58 | } 59 | \end{lstlisting} 60 | 61 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/MDSTN3.tex~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/MDSTN3.tex~ -------------------------------------------------------------------------------- /SCL-collection/SuperNova/MDSTNlogN.tex~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/MDSTNlogN.tex~ -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Manacher.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void manacher (char str[], int len[], int n) { 3 | len[0] = 1; 4 | for (int i = 1, j = 0; i < (n << 1) - 1; ++ i) { 5 | int p = i >> 1, 6 | q = i - p, 7 | r = ((j + 1) >> 1) + len[j] - 1; 8 | len[i] = r < q? 0: min(r - q + 1, len[(j << 1) - i]); 9 | while (p - len[i] > -1 and q + len[i] < n and str[p - len[i]] == str[q + len[i]]) { 10 | len[i] += 1; 11 | } 12 | if (q + len[i] - 1 > r) { 13 | j = i; 14 | } 15 | } 16 | } 17 | \end{lstlisting} 18 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Manacher.tex~: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void manacher (char str[], int len[], int n) { 3 | len[0] = 1; 4 | for (int i = 1, j = 0; i < (n << 1) - 1; ++ i) { 5 | int p = i >> 1, 6 | q = i - p, 7 | r = ((j + 1) >> 1) + len[j] - 1; 8 | len[i] = r < q? 0: min(r - q + 1, len[(j << 1) - i]); 9 | while (p - len[i] > -1 and q + len[i] < n and str[p - len[i]] == str[q + len[i]]) { 10 | len[i] += 1; 11 | } 12 | if (q + len[i] - 1 > r) { 13 | j = i; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/MillerRabbin2.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int strong_pseudo_primetest(long long n,int base) { 3 | long long n2=n-1,res; 4 | int s; s=0; 5 | while(n2%2==0) n2>>=1,s++; 6 | res=powmod(base,n2,n); 7 | if((res==1)||(res==n-1)) return 1; 8 | s--; 9 | while(s>=0) { 10 | res=mulmod(res,res,n); 11 | if(res==n-1) return 1; 12 | s--; 13 | } 14 | return 0; // n is not a strong pseudo prime 15 | } 16 | int isprime(long long n) { 17 | if(n<2) return 0; 18 | if(n<4) return 1; 19 | if(strong_pseudo_primetest(n,2)==0) return 0; 20 | if(strong_pseudo_primetest(n,3)==0) return 0; 21 | if(n<1373653LL) return 1; 22 | if(strong_pseudo_primetest(n,5)==0) return 0; 23 | if(n<25326001LL) return 1; 24 | if(strong_pseudo_primetest(n,7)==0) return 0; 25 | if(n==3215031751LL) return 0; 26 | if(n<25000000000LL) return 1; 27 | if(strong_pseudo_primetest(n,11)==0) return 0; 28 | if(n<2152302898747LL) return 1; 29 | if(strong_pseudo_primetest(n,13)==0) return 0; 30 | if(n<3474749660383LL) return 1; 31 | if(strong_pseudo_primetest(n,17)==0) return 0; 32 | if(n<341550071728321LL) return 1; 33 | if(strong_pseudo_primetest(n,19)==0) return 0; 34 | if(strong_pseudo_primetest(n,23)==0) return 0; 35 | if(strong_pseudo_primetest(n,29)==0) return 0; 36 | if(strong_pseudo_primetest(n,31)==0) return 0; 37 | if(strong_pseudo_primetest(n,37)==0) return 0; 38 | return 1; 39 | } 40 | \end{lstlisting} 41 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/MillerRabbin2.tex~: -------------------------------------------------------------------------------- 1 | int strong_pseudo_primetest(long long n,int base) { 2 | long long n2=n-1,res; 3 | int s; s=0; 4 | while(n2%2==0) n2>>=1,s++; 5 | res=powmod(base,n2,n); 6 | if((res==1)||(res==n-1)) return 1; 7 | s--; 8 | while(s>=0) { 9 | res=mulmod(res,res,n); 10 | if(res==n-1) return 1; 11 | s--; 12 | } 13 | return 0; // n is not a strong pseudo prime 14 | } 15 | int isprime(long long n) { 16 | if(n<2) return 0; 17 | if(n<4) return 1; 18 | if(strong_pseudo_primetest(n,2)==0) return 0; 19 | if(strong_pseudo_primetest(n,3)==0) return 0; 20 | if(n<1373653LL) return 1; 21 | if(strong_pseudo_primetest(n,5)==0) return 0; 22 | if(n<25326001LL) return 1; 23 | if(strong_pseudo_primetest(n,7)==0) return 0; 24 | if(n==3215031751LL) return 0; 25 | if(n<25000000000LL) return 1; 26 | if(strong_pseudo_primetest(n,11)==0) return 0; 27 | if(n<2152302898747LL) return 1; 28 | if(strong_pseudo_primetest(n,13)==0) return 0; 29 | if(n<3474749660383LL) return 1; 30 | if(strong_pseudo_primetest(n,17)==0) return 0; 31 | if(n<341550071728321LL) return 1; 32 | if(strong_pseudo_primetest(n,19)==0) return 0; 33 | if(strong_pseudo_primetest(n,23)==0) return 0; 34 | if(strong_pseudo_primetest(n,29)==0) return 0; 35 | if(strong_pseudo_primetest(n,31)==0) return 0; 36 | if(strong_pseudo_primetest(n,37)==0) return 0; 37 | return 1; 38 | } 39 | \end{lstlisting} 40 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/SCC.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int totID, totCol; 3 | int col[MAX_N], low[MAX_N], dfn[MAX_N]; 4 | int top, stack[MAX_N], instack[MAX_N]; 5 | 6 | int tarjan(int u) 7 | { 8 | low[u] = dfn[u] = ++ totID; 9 | instack[u] = true; stack[++ top] = u; 10 | 11 | int v; 12 | foreach(it, adj[u]) { 13 | v = it->first; 14 | if (dfn[v] == -1) 15 | low[u] = min(low[u], tarjan(v)); 16 | else if (instack[v]) 17 | low[u] = min(low[u], dfn[v]); 18 | } 19 | 20 | if (low[u] == dfn[u]) { 21 | do { 22 | v = stack[top --]; 23 | instack[v] = false; 24 | col[v] = totCol; 25 | } while(v != u); 26 | ++ totCol; 27 | } 28 | return low[u]; 29 | } 30 | 31 | void solve() 32 | { 33 | totID = totCol = top = 0; 34 | fill(dfn, dfn + N, 0); 35 | for(int i = 0; i < N; ++ i) 36 | if (! dfn[i]) 37 | tarjan(i); 38 | } 39 | \end{lstlisting} 40 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/SCL_KMP.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector KMP() 3 | { 4 | vector ans; 5 | nxt[0] = -1; 6 | nxt[1] = 0; 7 | for(int i = 2; i <= m; i++) 8 | { 9 | nxt[i] = nxt[i - 1]; 10 | while(nxt[i] >= 0 and st[i] != st[nxt[i] + 1]) 11 | nxt[i] = nxt[nxt[i]]; 12 | nxt[i]++; 13 | } 14 | for(int i = 1, p = 1; i <= n; i++) 15 | { 16 | while(p and str1[i] != st[p]) 17 | p = nxt[p - 1] + 1; 18 | p++; 19 | if(p == m + 1) p = nxt[m] + 1, ans.push_back(i - m); 20 | } 21 | return ans; 22 | } 23 | \end{lstlisting} 24 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/SCL_str_cyc_min_rep.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct cyc_string 3 | { 4 | int n, offset; 5 | char str[max_length]; 6 | char & operator [] (int x) 7 | {return str[((offset + x) % n)];} 8 | cyc_string(){offset = 0;} 9 | }; 10 | void minimum_circular_representation(cyc_string & a) 11 | { 12 | int i = 0, j = 1, dlt = 0, n = a.n; 13 | while(i < n and j < n and dlt < n) 14 | { 15 | if(a[i + dlt] == a[j + dlt]) dlt++; 16 | else 17 | { 18 | if(a[i + dlt] > a[j + dlt]) i += dlt + 1; else j += dlt + 1; 19 | dlt = 0; 20 | } 21 | } 22 | a.offset = min(i, j); 23 | } 24 | int main() 25 | {return 0;} 26 | \end{lstlisting} 27 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Simpson/.CIRU.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/Simpson/.CIRU.cpp.swp -------------------------------------------------------------------------------- /SCL-collection/SuperNova/Simpson/CIRU.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | #define MP make_pair 13 | #define PB push_back 14 | #define foreach(e,x) for(__typedef(x.begin()) e=x.begin(); e!=x.end(); ++e) 15 | 16 | typedef long long LL; 17 | typedef vector VI; 18 | typedef pair mapII; 19 | 20 | const int N = 1000 + 10; 21 | const double EPS = 1e-8; 22 | 23 | struct Circle 24 | { 25 | double x, y, r; 26 | } a[N]; 27 | 28 | int n; 29 | 30 | void solve() 31 | { 32 | for(int i = 0; i < n; ++ i) { 33 | scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].r); 34 | } 35 | } 36 | 37 | int main() 38 | { 39 | for( ; cin >> n; ) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/S三维旋转操作.tex: -------------------------------------------------------------------------------- 1 | a点绕Ob向量,逆时针旋转弧度angle,sin(angle),cos(angle)先求出来,减少精度问题。 2 | \begin{lstlisting} 3 | point e1,e2,e3; 4 | point Rotate( point a, point b, double angle ){ 5 | b.std();//单位化,注意b不能为(0,0,0) 6 | e3=b; double lens=a*e3;//dot(a,e3) 7 | e1=a - e3*lens; if (e1.len()>(1e-8)) e1.std(); else return a; 8 | e2=e1/e3; //det(e1,e3) 9 | double x1,y1,x,y; 10 | y1=a*e1; x1=a*e2; 11 | x=x1*cos(angle) - y1*sin(angle); 12 | y=x1*sin(angle) + y1*cos(angle); 13 | return e3*lens + e1*y + e2*x; 14 | } 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/S三维旋转操作.tex~: -------------------------------------------------------------------------------- 1 | a点绕Ob向量,逆时针旋转弧度angle,sin(angle),cos(angle)先求出来,减少精度问题。 2 | \begin{lstlisting} 3 | point e1,e2,e3; 4 | point Rotate( point a, point b, double angle ){ 5 | b.std();//单位化,注意b不能为(0,0,0) 6 | e3=b; double lens=a*e3;//dot(a,e3) 7 | e1=a - e3*lens; if (e1.len()>(1e-8)) e1.std(); else return a; 8 | e2=e1/e3; //det(e1,e3) 9 | double x1,y1,x,y; 10 | y1=a*e1; x1=a*e2; 11 | x=x1*cos(angle) - y1*sin(angle); 12 | y=x1*sin(angle) + y1*cos(angle); 13 | return e3*lens + e1*y + e2*x; 14 | } 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/S基本操作.tex~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/S基本操作.tex~ -------------------------------------------------------------------------------- /SCL-collection/SuperNova/acautomaton.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | 3 | struct acNode 4 | { 5 | int id; 6 | acNode *ch[26], *fail; 7 | } *totNode, *root, nodePool[MAX_V]; 8 | 9 | acNode* newNode() 10 | { 11 | acNode *now = totNode ++; 12 | now->id = 0; now->fail = 0; 13 | memset(now->ch, 0, sizeof now->ch); 14 | return now; 15 | } 16 | 17 | void acInsert(char *c, int id) 18 | { 19 | acNode *cur = root; 20 | while (*c) { 21 | int p = *c - 'A'; //change the index 22 | if (! cur->ch[p]) cur->ch[p] = newNode(); 23 | cur = cur->ch[p]; 24 | ++ c; 25 | } 26 | cur->id = id; 27 | } 28 | 29 | void getFail() 30 | { 31 | acNode *cur; 32 | queue Q; 33 | for(int i = 0; i < 26; ++ i) 34 | if (root->ch[i]) { 35 | root->ch[i]->fail = root; 36 | Q.push(root->ch[i]); 37 | } else root->ch[i] = root; 38 | while (! Q.empty()) { 39 | cur = Q.front(); Q.pop(); 40 | for(int i = 0; i < 26; ++ i) 41 | if (cur->ch[i]) { 42 | cur->ch[i]->fail = cur->fail->ch[i]; 43 | Q.push(cur->ch[i]); 44 | } else cur->ch[i] = cur->fail->ch[i]; 45 | } 46 | } 47 | \end{lstlisting} 48 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/aczidongji_shy.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int a[100001][27],fail[100001],last[100001],c[100001],l,father[100001],type[100001]; 10 | char can[1001]; 11 | 12 | inline void maketrie(){ 13 | memset(a,0,sizeof(a)); 14 | memset(type,0,sizeof(type)); 15 | memset(last,0,sizeof(last)); 16 | int n=strlen(can),now=0; 17 | l=0; 18 | for (int i=0;i tot) return; 20 | if (p < tot && val(p + 1) > val(p)) ++ p; 21 | if (val(p) > val(x)) 22 | exchange(p, x), fixDown(p); 23 | } 24 | void Update(int i, int x) { 25 | a[i] = x; 26 | fixUp(ind[i]); 27 | fixDown(ind[i]); 28 | } 29 | int top() { 30 | return h[1]; 31 | } 32 | void pop() { 33 | exchange(1, tot); 34 | -- tot; 35 | fixDown(1); 36 | } 37 | void insert(int i, int x) { 38 | ++ tot; 39 | h[tot] = i; 40 | ind[i] = tot; 41 | a[i] = x; 42 | fixUp(tot); 43 | } 44 | } H; 45 | \end{lstlisting} 46 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/c -------------------------------------------------------------------------------- /SCL-collection/SuperNova/c.in: -------------------------------------------------------------------------------- 1 | 1 1 2 | 1 3 | 1 4 | 2 5 | 6 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/c_ref.tex~: -------------------------------------------------------------------------------- 1 | \begin{enumerate} 2 | \item 开栈的命令 #pragma comment(linker, "/STACK:16777216"),交C++ 3 | \item ios::sync_with_stdio(false); 4 | \item \%o 八进制 \%h 十六进制 5 | \end{enumerate} 6 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/cheat sheet/cheat.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/cheat sheet/cheat.pdf -------------------------------------------------------------------------------- /SCL-collection/SuperNova/crt.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | LL x, y; 3 | void exGcd(LL a, LL b) 4 | { 5 | if (b == 0) { 6 | x = 1; 7 | y = 0; 8 | return; 9 | } 10 | exGcd(b, a % b); 11 | LL k = y; 12 | y = x - a / b * y; 13 | x = k; 14 | } 15 | 16 | LL inversion(LL a, LL b) 17 | { 18 | exGcd(a, b); 19 | return (x % b + b) % b; 20 | } 21 | 22 | LL CRT(vector m, vector a) 23 | { 24 | int N = m.size(); 25 | LL M = 1, ret = 0; 26 | for(int i = 0; i < N; ++ i) 27 | M *= m[i]; 28 | 29 | for(int i = 0; i < N; ++ i) { 30 | ret = (ret + (M / m[i]) * a[i] % M * inversion(M / m[i], m[i])) % M; 31 | } 32 | return ret; 33 | } 34 | \end{lstlisting} 35 | 36 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/decomposition.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Tree() 3 | { 4 | 5 | }; 6 | 7 | int father[MAX_N], size[MAX_N], depth[MAX_N]; 8 | int bfsOrd[MAX_N], pathId[MAX_N], ordInPath[MAX_N], sqn[MAX_N]; 9 | Tree *root[MAX_N]; 10 | 11 | void doBfs(int s) 12 | { 13 | int *que = bfsOrd; 14 | int qh = 0, qt = 0; 15 | father[s] = -1; depth[s] = 0; 16 | 17 | for(que[qt ++] = s; qh < qt; ) { 18 | int u = que[qh ++]; 19 | foreach(iter, adj[u]) { 20 | int v = *iter; 21 | if (v == father[u]) 22 | continue; 23 | father[v] = u; 24 | depth[v] = depth[u] + 1; 25 | que[qt ++] = v; 26 | } 27 | } 28 | } 29 | 30 | void doSplit() 31 | { 32 | for(int i = N - 1; i >= 0; -- i) { 33 | int u = bfsOrd[i]; 34 | size[u] = 1; 35 | foreach(iter, adj[u]) { 36 | int v = *iter; 37 | if (v == father[u]) 38 | continue; 39 | size[u] += size[v]; 40 | } 41 | } 42 | 43 | memset(pathId, -1, sizeof pathId); 44 | for(int i = 0; i < N; ++ i) { 45 | int top = bfsOrd[i]; 46 | if (pathId[top] != -1) 47 | continue; 48 | 49 | int cnt = 0; 50 | for(int u = top; u != -1; ) { 51 | sqn[cnt] = val[u]; 52 | ordInPath[u] = cnt; 53 | pathId[u] = top; 54 | ++ cnt; 55 | 56 | int next = -1; 57 | foreach(iter, adj[u]) { 58 | int v = *iter; 59 | if (v == father[u]) 60 | continue; 61 | if (next < 0 || size[next] < size[v]) 62 | next = v; 63 | } 64 | u = next; 65 | } 66 | 67 | root[top] = new Tree(0, cnt, sqn); 68 | } 69 | } 70 | 71 | void prepare() 72 | { 73 | doBfs(0); 74 | doSplit(); 75 | } 76 | 77 | \end{lstlisting} 78 | 79 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/dijkstra.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int used[MAX_N], dis[MAX_N]; 3 | void dijstra(int s) { 4 | fill(dis, dis + N, INF); dis[s] = 0; 5 | priority_queue > que; 6 | que.push(make_pair(-dis[s], s)); 7 | while (!que.empty()) { 8 | int u = que.top().second; que.pop(); 9 | if (used[u]) continue; 10 | used[u] = true; 11 | foreach(e, E[u]) 12 | if (dis[u] + e->w < dis[e->t]) { 13 | dis[e->t] = dis[u] + e->w; 14 | que.push(make_pair(-dis[e->t], e->t)); 15 | } 16 | } 17 | } 18 | \end{lstlisting} 19 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/farmland/a.in: -------------------------------------------------------------------------------- 1 | 3 2 | 4 3 | 1 0 0 2 2 4 4 | 2 0 1 2 1 3 5 | 3 1 1 2 2 4 6 | 4 1 0 2 3 1 7 | 4 8 | 12 9 | 1 2 6 3 9 7 2 10 | 2 5 6 4 5 3 1 8 11 | 3 3 5 2 4 2 12 | 4 3 4 2 3 5 13 | 5 4 4 2 4 2 14 | 6 7 4 1 8 15 | 7 2 3 2 8 1 16 | 8 5 3 5 7 2 9 12 6 17 | 9 1 2 3 11 8 1 18 | 10 3 2 1 11 19 | 11 2 1 3 10 9 12 20 | 12 6 1 2 8 11 21 | 4 22 | 3 23 | 1 2 2 2 2 3 24 | 2 1 1 2 1 3 25 | 3 4 1 2 1 2 26 | 4 27 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/leftist-tree.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Node 3 | { 4 | int dis, val; 5 | Node *ch[2]; 6 | } *null; 7 | 8 | Node* merge(Node *u, Node *v) 9 | { 10 | if (u == null) return v; 11 | if (v == null) return u; 12 | if (u->val < v->val) swap(u, v); 13 | u->ch[1] = merge(u->ch[1], v); 14 | if (u->ch[1]->dis > u->ch[0]->dis) 15 | swap(u->ch[1], u->ch[0]); 16 | u->dis = u->ch[1]->dis + 1; 17 | return u; 18 | } 19 | 20 | Node* newNode(int w) 21 | { 22 | Node *t = totNode ++; 23 | t->ch[0] = t->ch[1] = null; 24 | t->val = w; t->dis = 0; 25 | return t; 26 | } 27 | \end{lstlisting} 28 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/main.pdf -------------------------------------------------------------------------------- /SCL-collection/SuperNova/maxflow.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Edge 3 | { 4 | int t, c; 5 | Edge *n, *r; 6 | } *E[MAX_V], edges[MAX_M], *totEdge; 7 | 8 | Edge* makeEdge(int s, int t, int c) 9 | { 10 | Edge *e = totEdge ++; 11 | e->t = t; e->c = c; e->n = E[s]; 12 | return E[s] = e; 13 | } 14 | 15 | void addEdge(int s, int t, int c) 16 | { 17 | Edge *p = makeEdge(s, t, c), *q = makeEdge(t, s, 0); 18 | p->r = q; q->r = p; 19 | } 20 | 21 | int maxflow() 22 | { 23 | static int cnt [MAX_V]; 24 | static int h [MAX_V]; 25 | static int que [MAX_V]; 26 | static int aug [MAX_V]; 27 | static Edge *cur [MAX_V]; 28 | static Edge *prev [MAX_V]; 29 | fill(h, h + cntN, cntN); 30 | memset(cnt, 0, sizeof cnt); 31 | int qt = 0, qh = 0; h[T] = 0; 32 | for(que[qt ++] = T; qh < qt; ) { 33 | int u = que[qh ++]; 34 | ++ cnt[h[u]]; 35 | for(Edge *e = E[u]; e; e = e->n) 36 | if (e->r->c && h[e->t] == cntN) { 37 | h[e->t] = h[u] + 1; 38 | que[qt ++] = e->t; 39 | } 40 | } 41 | memcpy(cur, E, sizeof E); 42 | aug[S] = INF; Edge *e; 43 | int flow = 0, u = S; 44 | while (h[S] < cntN) { 45 | for(e = cur[u]; e; e = e->n) 46 | if (e->c && h[e->t] + 1 == h[u]) 47 | break; 48 | if (e) { 49 | int v = e->t; 50 | cur[u] = prev[v] = e; 51 | aug[v] = min(aug[u], e->c); 52 | if ((u = v) == T) { 53 | int by = aug[T]; 54 | while (u != S) { 55 | Edge *p = prev[u]; 56 | p->c -= by; 57 | p->r->c += by; 58 | u = p->r->t; 59 | } 60 | flow += by; 61 | } 62 | } else { 63 | if (!-- cnt[h[u]]) return flow; 64 | h[u] = cntN; 65 | for(e = E[u]; e; e = e->n) 66 | if (e->c && h[u] > h[e->t] + 1) 67 | h[u] = h[e->t] + 1, cur[u] = e; 68 | ++ cnt[h[u]]; 69 | if (u != S) u = prev[u]->r->t; 70 | } 71 | } 72 | return flow; 73 | } 74 | \end{lstlisting} 75 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/mincostflow.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int flow, cost; 3 | 4 | struct Edge 5 | { 6 | int t, c, w; 7 | Edge *n, *r; 8 | } *totEdge, edges[MAX_M], *E[MAX_V]; 9 | 10 | Edge* makeEdge(int s, int t, int c, int w) 11 | { 12 | Edge *e = totEdge ++; 13 | e->t = t; e->c = c; e->w = w; e->n = E[s]; 14 | return E[s] = e; 15 | } 16 | 17 | void addEdge(int s, int t, int c, int w) 18 | { 19 | Edge *st = makeEdge(s, t, c, w), *ts = makeEdge(t, s, 0, -w); 20 | st->r = ts; ts->r = st; 21 | } 22 | 23 | int SPFA() 24 | { 25 | static int que[MAX_V]; 26 | static int aug[MAX_V]; 27 | static int in[MAX_V]; 28 | static int dist[MAX_V]; 29 | static Edge *prev[MAX_V]; 30 | int qh = 0, qt = 0; 31 | 32 | int u, v; 33 | fill(dist, dist + cntN, INF); dist[S] = 0; 34 | fill(in, in + cntN, 0); in[S] = true; 35 | que[qt ++] = S; aug[S] = INF; 36 | for( ; qh != qt; ) { 37 | u = que[qh]; qh = (qh + 1) % MAX_N; 38 | for(Edge *e = E[u]; e; e = e->n) { 39 | if (! e->c) continue; 40 | v = e->t; 41 | if (dist[v] > dist[u] + e->w) { 42 | dist[v] = dist[u] + e->w; 43 | aug[v] = min(aug[u], e->c); 44 | prev[v] = e; 45 | if (! in[v]) { 46 | in[v] = true; 47 | if (qh != qt && dist[v] <= dist[que[qh]]) { 48 | qh = (qh - 1 + MAX_N) % MAX_N; 49 | que[qh] = v; 50 | } else { 51 | que[qt] = v; 52 | qt = (qt + 1) % MAX_N; 53 | } 54 | } 55 | } 56 | } 57 | in[u] = false; 58 | } 59 | 60 | if (dist[T] == INF) return false; 61 | cost += dist[T] * aug[T]; 62 | flow += aug[T]; 63 | for(u = T; u != S; ) { 64 | prev[u]->c -= aug[T]; 65 | prev[u]->r->c += aug[T]; 66 | u = prev[u]->r->t; 67 | } 68 | return true; 69 | } 70 | 71 | int minCostFlow() 72 | { 73 | flow = cost = 0; 74 | while(SPFA()); 75 | return cost; 76 | } 77 | \end{lstlisting} 78 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/missfont.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/missfont.log -------------------------------------------------------------------------------- /SCL-collection/SuperNova/prefixInverse.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void solve (int m) { 3 | int inv[m]; 4 | inv[1] = 1; 5 | for (int i = 2; i < m; ++ i) { 6 | inv[i] = ((long long)(m - m / i) * inv[m % i]) % m; 7 | } 8 | } 9 | \end{lstlisting} 10 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/q.log: -------------------------------------------------------------------------------- 1 | This is XeTeX, Version 3.1415926-2.4-0.9998 (TeX Live 2012/Debian) (format=xelatex 2013.10.29) 31 OCT 2013 01:08 2 | entering extended mode 3 | restricted \write18 enabled. 4 | %&-line parsing enabled. 5 | **--help 6 | (/usr/share/texlive/texmf-dist/tex/latex/tools/q.tex 7 | LaTeX2e <2011/06/27> 8 | Babel and hyphenation patterns for english, dumylang, nohyphenation, et 9 | hiopic, farsi, arabic, pinyin, croatian, bulgarian, ukrainian, russian, slovak, 10 | czech, danish, dutch, usenglishmax, ukenglish, finnish, french, basque, ngerma 11 | n, german, swissgerman, ngerman-x-2012-05-30, german-x-2012-05-30, monogreek, g 12 | reek, ibycus, ancientgreek, hungarian, bengali, tamil, hindi, telugu, gujarati, 13 | sanskrit, malayalam, kannada, assamese, marathi, oriya, panjabi, italian, lati 14 | n, latvian, lithuanian, mongolian, mongolianlmc, nynorsk, bokmal, indonesian, e 15 | speranto, coptic, welsh, irish, interlingua, serbian, serbianc, slovenian, friu 16 | lan, romansh, estonian, romanian, armenian, uppersorbian, turkish, afrikaans, i 17 | celandic, kurmanji, polish, portuguese, galician, catalan, spanish, swedish, th 18 | ai, loaded. 19 | File ignored 20 | ) 21 | ! Emergency stop. 22 | <*> --help 23 | 24 | *** (job aborted, no legal \end found) 25 | 26 | 27 | Here is how much of TeX's memory you used: 28 | 6 strings out of 494003 29 | 160 string characters out of 3152808 30 | 48083 words of memory out of 3000000 31 | 3367 multiletter control sequences out of 15000+200000 32 | 3640 words of font info for 14 fonts, out of 3000000 for 9000 33 | 1144 hyphenation exceptions out of 8191 34 | 5i,0n,1p,86b,8s stack positions out of 5000i,500n,10000p,200000b,50000s 35 | No pages of output. 36 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/rho.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | typedef long long LL; 3 | 4 | LL modMul(LL a, LL b, LL P) 5 | { 6 | LL ret = 0; 7 | for( ; a; a >>= 1) { 8 | if (a & 1) { 9 | ret += b; 10 | if (ret >= P) ret -= P; 11 | } 12 | b <<= 1; 13 | if (b >= P) b -= P; 14 | } 15 | return ret; 16 | } 17 | 18 | LL modPow(LL a, LL u, LL P) 19 | { 20 | LL ret = 1; 21 | for( ; u; u >>= 1, a = modMul(a, a, P)) 22 | if (u & 1) ret = modMul(ret, a, P); 23 | return ret; 24 | } 25 | 26 | int millerRabin(LL N) 27 | { 28 | if (N == 2) return true; 29 | LL t = 0, u = N - 1, x, y, a; 30 | for( ; ! (u & 1); ++ t, u >>= 1) ; 31 | for(int k = 0; k < 10; ++ k) { 32 | a = rand() % (N - 2) + 2; 33 | x = modPow(a, u, N); 34 | for(int i = 0; i < t; ++ i, x = y) { 35 | y = modMul(x, x, N); 36 | if (y == 1 && x > 1 && x < N - 1) return false; 37 | } 38 | if (x != 1) return false; 39 | } 40 | return true; 41 | } 42 | 43 | LL gcd(LL a, LL b) 44 | { 45 | return ! b ? a : gcd(b, a % b); 46 | } 47 | 48 | LL pollardRho(LL N) 49 | { 50 | LL i = 1, x = rand() % N; 51 | LL y = x, k = 2, d = 1; 52 | do { 53 | d = gcd(x - y + N, N); 54 | if (d != 1 && d != N) return d; 55 | if (++ i == k) y = x, k <<= 1; 56 | x = (modMul(x, x, N) - 1 + N) % N; 57 | } while (y != x); 58 | return N; 59 | } 60 | 61 | void getFactor(LL N) 62 | { 63 | if (N < 2) return; 64 | if (millerRabin(N)) { 65 | //do some operations 66 | return; 67 | } 68 | LL x = pollardRho(N); 69 | getFactor(x); 70 | getFactor(N / x); 71 | } 72 | \end{lstlisting} 73 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/segment-tree.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Tree 3 | { 4 | int l, r; 5 | Tree *ch[2]; 6 | Tree() {} 7 | Tree(int _l, int _r, int *sqn) { 8 | l = _l; r = _r; 9 | if (l + 1 == r) 10 | return; 11 | int mid = l + r >> 1; 12 | ch[0] = new Tree(l, mid, sqn); 13 | ch[1] = new Tree(mid, r, sqn); 14 | } 15 | 16 | void insert(int p, int x) { 17 | if (p < l || p >= r) 18 | return; 19 | //some operations 20 | if (l + 1 == r) 21 | return; 22 | ch[0]->insert(p, x); 23 | ch[1]->insert(p, x); 24 | } 25 | 26 | int query(int _l, int _r, int x) { 27 | if (_r <= l || _l >= r) 28 | return 0; 29 | if (_l <= l && _r >= r) 30 | // return information in [l, r) 31 | //merge ch[0]->query(_l, _r, x), ch[1]->query(_l, _r, x) and return 32 | } 33 | }; 34 | \end{lstlisting} 35 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/suffix-array.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const int MAX_N = 1000000 + 10; 3 | 4 | int rank[MAX_N], height[MAX_N]; 5 | 6 | int cmp(int *x, int a, int b, int d) 7 | { 8 | return x[a] == x[b] && x[a + d] == x[b + d]; 9 | } 10 | 11 | void doubling(int *a, int N, int M) 12 | { 13 | static int sRank[MAX_N], tmpA[MAX_N], tmpB[MAX_N]; 14 | int *x = tmpA, *y = tmpB; 15 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 16 | for(int i = 0; i < N; ++ i) ++ sRank[x[i] = a[i]]; 17 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 18 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[i]]] = i; 19 | 20 | for(int d = 1, p = 0; p < N; M = p, d <<= 1) { 21 | p = 0; for(int i = N - d; i < N; ++ i) y[p ++] = i; 22 | for(int i = 0; i < N; ++ i) 23 | if (sa[i] >= d) y[p ++] = sa[i] - d; 24 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 25 | for(int i = 0; i < N; ++ i) ++ sRank[x[i]]; 26 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 27 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[y[i]]]] = y[i]; 28 | swap(x, y); x[sa[0]] = 0; p = 1; 29 | for(int i = 1; i < N; ++ i) 30 | x[sa[i]] = cmp(y, sa[i], sa[i - 1], d) ? p - 1 : p ++; 31 | } 32 | } 33 | 34 | void calcHeight() 35 | { 36 | for(int i = 0; i < N; ++ i) rank[sa[i]] = i; 37 | int cur = 0; 38 | for(int i = 0; i < N; ++ i) 39 | if (rank[i]) { 40 | if (cur) cur --; 41 | for( ; a[i + cur] == a[sa[rank[i] - 1] + cur]; ++ cur); 42 | height[rank[i]] = cur; 43 | } 44 | } 45 | \end{lstlisting} 46 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/suffix-automaton.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct State 3 | { 4 | int val; 5 | State *suf, *go[26]; 6 | } *root, *last; 7 | 8 | State statePool[MAX_N], *curState; 9 | 10 | void extend(int w) 11 | { 12 | State *p = last, *np = curState ++; 13 | np->val = p->val + 1; 14 | for( ; p && ! p->go[w]; p = p->suf) 15 | p->go[w] = np; 16 | if (! p) 17 | np->suf = root; 18 | else { 19 | State *q = p->go[w]; 20 | if (q->val == p->val + 1) 21 | np->suf = q; 22 | else { 23 | State *nq = curState ++; 24 | nq->val = p->val + 1; 25 | memcpy(nq->go, q->go, sizeof q->go); 26 | nq->suf = q->suf; 27 | q->suf = np->suf = nq; 28 | for( ; p && p->go[w] == q; p = p->suf) 29 | p->go[w] = nq; 30 | } 31 | } 32 | last = np; 33 | } 34 | \end{lstlisting} 35 | 36 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/tmp.in: -------------------------------------------------------------------------------- 1 | 2 2 | 0.0 0.0 3 | 3 0 4 | 5 5 | 0 0 6 | 0 1 7 | 1 0 8 | 1 1 9 | 2 2 10 | 1 11 | 0 0 12 | 0 13 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/tmp2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/tmp2 -------------------------------------------------------------------------------- /SCL-collection/SuperNova/tmp2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a = 2; 7 | printf("%p\n", &a); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/tmpSGU332/a.in: -------------------------------------------------------------------------------- 1 | 4 2 | 0 0 3 | 1 0 4 | 1 1 5 | 0 1 6 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/treap.tex: -------------------------------------------------------------------------------- 1 | 2 | \begin{lstlisting} 3 | struct Node *null; 4 | 5 | struct Node 6 | { 7 | int key, val, size; 8 | Node *ch[2]; 9 | Node() { 10 | key = INT_MAX; 11 | val = size = 0; 12 | } 13 | Node(int _val) { 14 | size = 1; 15 | val = _val; 16 | key = bigRand(); 17 | ch[0] = ch[1] = null; 18 | } 19 | int bigRand() { 20 | return rand() * RAND_MAX + rand(); 21 | } 22 | void update() { 23 | size = ch[0]->size + ch[1]->size + 1; 24 | } 25 | }; 26 | 27 | struct Treap 28 | { 29 | Node *root; 30 | Treap() { 31 | root = null; 32 | } 33 | void rot(Node *&t, int d) { 34 | Node *p = t->ch[d]; t->ch[d] = p->ch[! d]; p->ch[! d] = t; 35 | t->update(); p->update(); 36 | t = p; 37 | } 38 | 39 | void insert(Node *&t, int x) { 40 | if (t == null) { 41 | t = new Node(x); 42 | return; 43 | } 44 | int dir = x >= t->val; 45 | insert(t->ch[dir], x); 46 | if (t->ch[dir]->key < t->key) 47 | rot(t, dir); 48 | else 49 | t->update(); 50 | } 51 | 52 | void erase(Node *&t, int x) { 53 | if (t == null) 54 | return; 55 | if (t->val == x) { 56 | int dir = t->ch[1]->key < t->ch[0]->key; 57 | if (t->ch[dir] == null) { 58 | delete t; 59 | t = null; 60 | return; 61 | } 62 | rot(t, dir); 63 | erase(t->ch[! dir], x); 64 | t->update(); 65 | return; 66 | } 67 | bool dir = x > t->val; 68 | erase(t->ch[dir], x); 69 | t->update(); 70 | } 71 | 72 | void insert(int x) { 73 | insert(root, x); 74 | } 75 | 76 | void erase(int x) { 77 | erase(root, x); 78 | } 79 | }; 80 | \end{lstlisting} 81 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/vimrc.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | set nu ai ci si mouse=a ts=4 sts=4 sw=4 3 | 4 | nmap ggVG 5 | vmap "+y 6 | 7 | nmap : vs %<.in 8 | nmap : !./%< < %<.in 9 | nmap : make %< 10 | 11 | nmap : !gedit % 12 | nmap : !./%< 13 | nmap : !java %< < %<.in 14 | nmap : !javac % 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/vimrc.tex~: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | set nu ai ci si et mouse=a ts=4 sts=4 sw=4 3 | 4 | nmap ggVG 5 | vmap "+y 6 | 7 | nmap : vs %<.in 8 | nmap : !./%< < %<.in 9 | nmap : make %< 10 | 11 | nmap : !gedit % 12 | nmap : !./%< 13 | nmap : !java %< < %<.in 14 | nmap : !javac % 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/z.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void z(char *s, int *next, int N) 3 | { 4 | int j = 0, k = 1; 5 | while (j + 1 < N && s[j] == s[j + 1]) ++ j; 6 | next[0] = N - 1; next[1] = j; 7 | for(int i = 2; i < N; ++ i) { 8 | int far = k + next[k] - 1, L = next[i - k]; 9 | if (L < far - i + 1) next[i] = L; 10 | else { 11 | j = max(0, far - i + 1); 12 | while (i + j < N && s[j] == s[i + j]) ++ j; 13 | next[i] = j; k = i; 14 | } 15 | } 16 | } 17 | \end{lstlisting} 18 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/三维几何/copyseraphim.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/三维几何/copyseraphim.cpp -------------------------------------------------------------------------------- /SCL-collection/SuperNova/三维几何/tmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/三维几何/tmp -------------------------------------------------------------------------------- /SCL-collection/SuperNova/上下界流建图方法.tex: -------------------------------------------------------------------------------- 1 | 上下界无源汇可行流: 不用添T—>S,判断是否流量平衡\\ 2 | 上下界无源汇可行流: 添T—>S(下界0,上界oo),判断是否流量平衡\\ 3 | 上下界最小流:不添T—>S先流一遍,再添T—>S(下界0,上界oo)在残图上流一遍,答案为S—>T的流量值\\ 4 | 上下界最大流: 添T—>S(下界0,上界oo)流一遍,再在残图上流一遍S到T的最大流,答案为前者的S—>T的值+残图中S—>T的最大流\\ 5 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/上下界流建图方法.tex~: -------------------------------------------------------------------------------- 1 | 上下界无源汇可行流: 不用添T—>S,判断是否流量平衡 2 | 上下界无源汇可行流: 添T—>S(下界0,上界oo),判断是否流量平衡 3 | 上下界最小流:不添T—>S先流一遍,再添T—>S(下界0,上界oo)在残图上流一遍,答案为S—>T的流量值 4 | 上下界最大流: 添T—>S(下界0,上界oo)流一遍,再在残图上流一遍S到T的最大流,答案为前者的S—>T的值+残图中S—>T的最大流 5 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/几何公式.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/几何公式.log -------------------------------------------------------------------------------- /SCL-collection/SuperNova/判断多个圆是否存在交集/a.in: -------------------------------------------------------------------------------- 1 | 66 25 88 2 | 4 3 | 65 7 4 | 7 13 5 | 52 28 6 | 57 78 7 | 66 49 29 8 | 7 9 | 3 4 10 | 69 12 11 | 50 93 12 | 77 39 13 | 49 77 14 | 35 2 15 | 88 61 16 | 3 55 38 17 | 4 18 | 90 56 19 | 50 98 20 | 21 55 21 | 78 79 22 | 85 44 80 23 | 5 24 | 80 83 25 | 70 50 26 | 95 73 27 | 95 24 28 | 12 97 29 | 53 99 99 30 | 5 31 | 61 54 32 | 49 51 33 | 49 91 34 | 7 99 35 | 89 29 36 | 6 68 60 37 | 2 38 | 64 40 39 | 6 45 40 | 23 28 47 41 | 1 42 | 1 42 43 | 46 66 91 44 | 10 45 | 65 90 46 | 93 78 47 | 44 94 48 | 82 45 49 | 86 89 50 | 45 27 51 | 70 3 52 | 47 30 53 | 95 12 54 | 70 53 55 | 9 45 81 56 | 9 57 | 67 35 58 | 2 13 59 | 53 94 60 | 13 70 61 | 84 58 62 | 49 81 63 | 5 31 64 | 26 43 65 | 72 23 66 | 70 43 27 67 | 1 68 | 25 74 69 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/判断多个圆是否存在交集/a.out: -------------------------------------------------------------------------------- 1 | 0.00 2 | X 3 | 49.48 4 | 10.21 5 | 0.00 6 | 4.41 7 | 0.00 8 | 0.00 9 | 0.00 10 | 27.64 11 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/判断多个圆是否存在交集/b.out: -------------------------------------------------------------------------------- 1 | 0.00 2 | X 3 | 49.48 4 | 10.21 5 | 0.00 6 | 4.40 7 | 0.00 8 | 0.00 9 | 0.00 10 | 27.64 11 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/判断多个圆是否存在交集/check.sh: -------------------------------------------------------------------------------- 1 | make a 2 | make b 3 | make gen 4 | 5 | $i 6 | 7 | while [ true ] 8 | do 9 | echo $((i=i+1)) 10 | ./gen > a.in 11 | ./a < a.in > a.out 12 | ./b < a.in > b.out 13 | if ! diff a.out b.out 14 | then 15 | echo Wrong 16 | break 17 | fi 18 | done 19 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/判断多个圆是否存在交集/gen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | #define MP make_pair 13 | #define PB push_back 14 | #define foreach(e,x) for(__typedef(x.begin()) e=x.begin(); e!=x.end(); ++e) 15 | 16 | typedef long long LL; 17 | typedef vector VI; 18 | typedef pair mapII; 19 | 20 | const int N = 100000 + 10; 21 | const double EPS = 1e-8; 22 | 23 | int sx, sy, d; 24 | 25 | void solve() 26 | { 27 | sx = rand() % 100; sy = rand() % 100; 28 | d = rand() % 100; 29 | int n = rand() % 10 + 1; 30 | cout << sx << ' ' << sy << ' ' << d << endl; 31 | cout << n << endl; 32 | for(int i = 0; i < n; ++ i) { 33 | int x = rand() % 100, y = rand() % 100; 34 | cout << x << ' ' << y << endl; 35 | } 36 | } 37 | 38 | int main() 39 | { 40 | srand(time(0)); 41 | int test = 10; 42 | for(int i = 0; i < test; ++ i) 43 | solve(); 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/多少个点在多边形内.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | //rn中的标号必须逆时针给出。一开始要旋转坐标,保证同一个x值上只有一个点。正向减点, 3 | //反向加点。num[i][j]=num[j][i]=严格在这根线下方的点。 on[i][j]=on[j][i]=严格 4 | //在线段上的点,包括两个端点。若有回边的话注意计算onit的方法,不要多算了线段上的点。 5 | int ans=0,z,onit=0,lows=0; 6 | rep(z,t) { 7 | i=rn[z]; j=rn[z+1]; onit+=on[i][j]-1; 8 | if (a[j].x>a[i].x){ans-=num[i][j];lows+=on[i][j]-1;} 9 | else ans+=num[i][j]; 10 | } 11 | //ans-lows+1 is inside. 只会多算一次正向上的点(除去最左和最右的点)。Lows只算了除开最左边的点,但会多算最右边的点,所以要再加上1. 12 | printf("%d\n",ans-lows+1+ onit); 13 | \end{lstlisting} 14 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/多项式求根.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const double error=1e-12; 3 | const double infi=1e+12; 4 | double a[10],x[10]; 5 | int n; 6 | int sign(double x) { 7 | return (x<-error)?(-1):(x>error); 8 | } 9 | double f(double a[],int n,double x) { 10 | double tmp=1,sum=0; 11 | for (int i=0;i<=n;i++) { 12 | sum=sum+a[i]*tmp; 13 | tmp=tmp*x; 14 | } 15 | return sum; 16 | } 17 | double binary(double l,double r,double a[],int n) { 18 | int sl=sign(f(a,n,l)),sr=sign(f(a,n,r)); 19 | if (sl==0) return l; 20 | if (sr==0) return r; 21 | if (sl*sr>0) return infi; 22 | while (r-l>error) { 23 | double mid=(l+r)/2; 24 | int ss=sign(f(a,n,mid)); 25 | if (ss==0) return mid; 26 | if (ss*sl>0) l=mid; else r=mid; 27 | } 28 | return l; 29 | } 30 | void solve(int n,double a[],double x[],int &nx) { 31 | if (n==1) { 32 | x[1]=-a[0]/a[1]; 33 | nx=1; 34 | return; 35 | } 36 | double da[10],dx[10]; 37 | int ndx; 38 | for (int i=n;i>=1;i--) da[i-1]=a[i]*i; 39 | solve(n-1,da,dx,ndx); 40 | nx=0; 41 | if (ndx==0) { 42 | double tmp=binary(-infi,infi,a,n); 43 | if (tmp=0;i--) scanf("%lf",&a[i]); 59 | int nx; 60 | solve(n,a,x,nx); 61 | for (int i=1;i<=nx;i++) printf("%0.6lf\n",x[i]); 62 | return 0; 63 | } 64 | \end{lstlisting} 65 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示.tex: -------------------------------------------------------------------------------- 1 | 传入字符串s,返回i,表示以i开始的循环串字典序最小,但不保证i在同样字典序最小的循环串里起始位置最小 2 | \begin{lstlisting} 3 | int minCycle(char *a) 4 | { 5 | int n = strlen(a); 6 | for(int i = 0; i < n; ++ i) { 7 | a[i + n] = a[i]; 8 | } 9 | a[n + n] = 0; 10 | int i = 0, j = 1, k = 0; 11 | do { 12 | for(k = 0; a[i + k] == a[j + k]; ++ k); 13 | if (a[i + k] > a[j + k]) i = i + k + 1; 14 | else j = j + k + 1; 15 | j += i == j; 16 | if (i > j) swap(i, j); 17 | } while(j < n); 18 | return i; 19 | } 20 | \end{lstlisting} 21 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int minCycle(char *a) 8 | { 9 | int n = strlen(a); 10 | for(int i = 0; i < n; ++ i) { 11 | a[i + n] = a[i]; 12 | } 13 | a[n + n] = 0; 14 | int i = 0, j = 1, k = 0; 15 | do { 16 | for(k = 0; a[i + k] == a[j + k]; ++ k); 17 | if (a[i + k] > a[j + k]) i = i + k + 1; 18 | else j = j + k + 1; 19 | j += i == j; 20 | if (i > j) swap(i, j); 21 | } while(j < n); 22 | return i; 23 | } 24 | 25 | char s[10000]; 26 | 27 | int main() 28 | { 29 | gets(s); 30 | int n = strlen(s); 31 | int k = minCycle(s); 32 | for(int i = 0; i < n; ++ i) { 33 | putchar(s[(i + k) % n]); 34 | } 35 | cout << endl; 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/a.in: -------------------------------------------------------------------------------- 1 | aabbbaaabbbaabbbaabbabbaabbbabbababbbababaaaabbabaaabbabaaaabbabaaababbbbbbbbbaabaabbba 2 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/字符串的最小表示/a.out -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/check.sh: -------------------------------------------------------------------------------- 1 | make gen 2 | make force 3 | make a 4 | $i 5 | while [ true ] 6 | do 7 | echo $((i=i+1)) 8 | ./gen > a.in 9 | ./a < a.in > a.out 10 | ./force < a.in > force.out 11 | if ! diff a.out force.out 12 | then 13 | echo Wrong 14 | break 15 | fi 16 | done 17 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/force.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s; 8 | cin >> s; 9 | int n = s.length(); 10 | string ret = s; 11 | s = s + s; 12 | for(int i = 0; i < n; ++ i) { 13 | string tmp = s.substr(i, n); 14 | if (tmp < ret) ret = tmp; 15 | } 16 | cout << ret << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/force.in: -------------------------------------------------------------------------------- 1 | abaaba 2 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/force.out: -------------------------------------------------------------------------------- 1 | aaaabbabaaababbbbbbbbbaabaabbbaaabbbaaabbbaabbbaabbabbaabbbabbababbbababaaaabbabaaabbab 2 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/字符串的最小表示/gen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | srand(time(0)); 11 | int n = rand() % 1000 + 1; 12 | for(int i = 0; i < n; ++ i) { 13 | putchar(rand() % 2 + 'a'); 14 | } 15 | putchar('\n'); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/斜线下格点统计.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | LL solve(LL n, LL a, LL b, LL m){ 3 | //计算for (int i=0;i0 5 | //printf("%lld %lld %lld %lld\n", n, a, b, m); 6 | if(b == 0){ 7 | return n * (a / m); 8 | } 9 | if(a >= m){ 10 | return n * (a / m) + solve(n, a % m, b, m); 11 | } 12 | if(b >= m){ 13 | return (n - 1) * n / 2 * (b / m) + solve(n, a, b % m, m); 14 | } 15 | LL q = (a + b * n) / m; 16 | return solve(q, (a + b * n) % m, m, b); 17 | } 18 | \end{lstlisting} 19 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/无向图最小割.cpp: -------------------------------------------------------------------------------- 1 | const int V = 100; 2 | #define typec int 3 | const typec inf = 0x3f3f3f; // max of res 4 | const typec maxw = 1000; // maximum edge weight 5 | typec g[V][V], w[V]; //g[i][j] = g[j][i] 6 | int a[V], v[V], na[V]; 7 | typec mincut(int n) { 8 | int i, j, pv, zj; 9 | typec best = maxw * n * n; 10 | for (i = 0; i < n; i++) v[i] = i; // vertex: 0 ~ n-1 11 | while (n > 1) { 12 | for (a[v[0]] = 1, i = 1; i < n; i++) { 13 | a[v[i]] = 0; na[i - 1] = i; 14 | w[i] = g[v[0]][v[i]]; 15 | } 16 | for (pv = v[0], i = 1; i < n; i++) { 17 | for (zj = -1, j = 1; j < n; j++) 18 | if (!a[v[j]] && (zj < 0 || w[j] > w[zj])) 19 | zj = j; 20 | a[v[zj]] = 1; 21 | if (i == n - 1) { 22 | if (best > w[zj]) best = w[zj]; 23 | for (i = 0; i < n; i++) 24 | g[v[i]][pv] = g[pv][v[i]] += 25 | g[v[zj]][v[i]]; 26 | v[zj] = v[--n]; 27 | break; 28 | } 29 | pv = v[zj]; 30 | for (j = 1; j < n; j++) 31 | if(!a[v[j]]) 32 | w[j] += g[v[zj]][v[j]]; 33 | } 34 | } 35 | return best; 36 | } 37 | 38 | int main() 39 | { 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/无向图最小割.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const int V = 100; 3 | #define typec int 4 | const typec inf = 0x3f3f3f; // max of res 5 | const typec maxw = 1000; // maximum edge weight 6 | typec g[V][V], w[V]; //g[i][j] = g[j][i] 7 | int a[V], v[V], na[V]; 8 | typec mincut(int n) { 9 | int i, j, pv, zj; 10 | typec best = maxw * n * n; 11 | for (i = 0; i < n; i++) v[i] = i; // vertex: 0 ~ n-1 12 | while (n > 1) { 13 | for (a[v[0]] = 1, i = 1; i < n; i++) { 14 | a[v[i]] = 0; na[i - 1] = i; 15 | w[i] = g[v[0]][v[i]]; 16 | } 17 | for (pv = v[0], i = 1; i < n; i++) { 18 | for (zj = -1, j = 1; j < n; j++) 19 | if (!a[v[j]] && (zj < 0 || w[j] > w[zj])) 20 | zj = j; 21 | a[v[zj]] = 1; 22 | if (i == n - 1) { 23 | if (best > w[zj]) best = w[zj]; 24 | for (i = 0; i < n; i++) 25 | g[v[i]][pv] = g[pv][v[i]] += 26 | g[v[zj]][v[i]]; 27 | v[zj] = v[--n]; 28 | break; 29 | } 30 | pv = v[zj]; 31 | for (j = 1; j < n; j++) 32 | if(!a[v[j]]) 33 | w[j] += g[v[zj]][v[j]]; 34 | } 35 | } 36 | return best; 37 | } 38 | 39 | int main() 40 | { 41 | return 0; 42 | } 43 | \end{lstlisting} 44 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swn -------------------------------------------------------------------------------- /SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swo -------------------------------------------------------------------------------- /SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/最小球覆盖/.ser.cpp.swp -------------------------------------------------------------------------------- /SCL-collection/SuperNova/最小球覆盖/ser.in: -------------------------------------------------------------------------------- 1 | 4 2 | 10.00000 10.00000 10.00000 3 | 20.00000 10.00000 10.00000 4 | 20.00000 20.00000 10.00000 5 | 10.00000 20.00000 10.00000 6 | 4 7 | 10.00000 10.00000 10.00000 8 | 10.00000 50.00000 50.00000 9 | 50.00000 10.00000 50.00000 10 | 50.00000 50.00000 10.00000 11 | 0 12 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/有根树的同构.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/有根树的同构.tex -------------------------------------------------------------------------------- /SCL-collection/SuperNova/杂知识.tex: -------------------------------------------------------------------------------- 1 | \subsection*{牛顿迭代} 2 | x1=x0-func(x0)/func1(x0);进行牛顿迭代计算\\ 3 | 我们要求 f(x)=0 的解。func(x)为原方程,func1 为原方程的导数方程 4 | \subsection*{图同构 Hash} 5 | \begin{displaymath} 6 | F_t(i) = (F_{t - 1}(i) * A + \sum_{i \to j} (F_{t - 1}(j) * B) + \sum_{j \to i} (F_{t - 1}(j) * C) + D * (i == a)) \mod P 7 | \end{displaymath} 8 | 枚举点a, 迭代K次后求得的$F_k(a)$就是a点所对应的hash值。\\ 9 | 其中 K、A、B、C、D、P 为 hash 参数,可自选。 10 | 11 | \subsection*{圆上有整点的充要条件} 12 | 设正整数 n 的质因数分解为 $n = \Pi p_i^{a_i}$,则 $x^2+y^2=n$ 有整数解的充要条件是 n 中不存在形 13 | 如 $p_i \mod 4 = 3$ 且指数 $a_i$ 为奇数的质因数 $p_i$ 14 | 15 | \subsection*{Pick 定理} 16 | 简单多边形,不自交。(严格在多边形内部的整点数*2 + 在边上的整点数– 2)/2 = 面积 17 | 18 | \subsection*{图定理} 19 | 定理 1:最小覆盖数 = 最大匹配数\\ 20 | 定理 2:最大独立集 S 与 最小覆盖集 T 互补。\\ 21 | 算法:\\ 22 | 1. 做最大匹配,没有匹配的空闲点$\in S$\\ 23 | 2. 如果 $u \in S$ 那么 u 的临点必然属于 T\\ 24 | 3. 如果一对匹配的点中有一个属于 T 那么另外一个属于 S\\ 25 | 4. 还不能确定的,把左子图的放入 S,右子图放入 T\\ 26 | 算法结束\\ 27 | 28 | \subsection*{梅森素数} 29 | p 是素数且 $2^p-1$ 的是素数,n 不超过 258 的全部梅森素数终于确定!是:\\ 30 | n=2,3,5,7,13,17,19,31,61,89,107,127 31 | 32 | \subsection*{上下界网络流} 33 | 有上下界网络流,求可行流部分,增广的流量不是实际流量。若要求实际流量应该强算一遍源点出去的流量。\\ 34 | 求最小下届网络流:\\ 35 | 方法一:加 t-s 的无穷大流,求可行流,然后把边反向后(减去下届网络流),在残留网络中从汇到源做最大流。\\ 36 | 方法二:在求可行流的时候,不加从汇到源的无穷大边,得到最大流 X, 加上从汇到源无穷大边后,再求最大流得到 Y。那么 Y 即是答案最小下界网络流。\\ 37 | 原因:感觉上是在第一遍已经把内部都消耗光了,第二遍是必须的流量。 38 | 39 | \subsection*{平面图定理} 40 | 平面图一定存在一个度小于等于 5 的点,且可以四染色\\ 41 | ( 欧拉公式 ) 设 G 是连通的平面图,n,m,r分别是其顶点数、边数和面数,n-m+r=2\\ 42 | 极大平面图 $m\leq 3n-6$ 43 | 44 | \subsection*{Fibonacci相关结论} 45 | gcd(F[n],F[m])=F[gcd(n,m)]\\ 46 | Fibonacci 质数(和前面所有的 Fibonacci 数互质), 下标为质数或4\\ 47 | 定理:如果 a 是 b 的倍数,那么 F[a] 是 F[b] 的倍数。\\ 48 | 49 | \subsection*{二次剩余} 50 | p 为奇素数,若(a,p)=1, a 为 p 的二次剩余必要充分条件为 $a^{(p-1)/2} \mod p=1$.(否则为$p-1$)\\ 51 | p 为奇素数, $x^b=a(\mod p)$,a 为 p 的 b 次剩余的必要充分条件为若 $a^{(p-1)/ (p-1, b)} \mod p=1$. 52 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/杂知识.tex~: -------------------------------------------------------------------------------- 1 | \subsection*{牛顿迭代} 2 | x1=x0-func(x0)/func1(x0);进行牛顿迭代计算\\ 3 | 我们要求 f(x)=0 的解。func(x)为原方程,func1 为原方程的导数方程 4 | \subsection*{图同构 Hash} 5 | \begin{displaymath} 6 | F_t(i) = () \mod P 7 | \end{displaymath} 8 | 枚举点a, 迭代K次后求得的$F_k(a)$就是a点所对应的hash值。\\ 9 | 其中 K、A、B、C、D、P 为 hash 参数,可自选。 10 | 11 | \subsection*{圆上有整点的充要条件} 12 | 设正整数 n 的质因数分解为 $n = \Pi p_i^{a_i}$,则 $x^2+y^2=n$ 有整数解的充要条件是 n 中不存在形 13 | 如 $p_i \mod 4 = 3$ 且指数 $a_i$ 为奇数的质因数 $p_i$ 14 | 15 | \subsection*{Pick 定理} 16 | 简单多边形,不自交。(严格在多边形内部的整点数*2 +在边上的整点数– 2)/2 =面积 17 | 18 | \subsection*{图定理} 19 | 定理 1:最小覆盖数 = 最大匹配数\\ 20 | 定理 2:最大独立集 S 与 最小覆盖集 T 互补。\\ 21 | 算法:\\ 22 | 1. 做最大匹配,没有匹配的空闲点∈S\\ 23 | 2. 如果 u∈S 那么 u 的临点必然属于 T\\ 24 | 3. 如果一对匹配的点中有一个属于 T 那么另外一个属于 S\\ 25 | 4. 还不能确定的,把左子图的放入 S,右子图放入 T\\ 26 | 算法结束\\ 27 | 28 | \subsection*{梅森素数} 29 | p 是素数且 $2^p-1$ 的是素数,n 不超过 258 的全部梅森素数终于确定!是:\\ 30 | n=2,3,5,7,13,17,19,31,61,89,107,127 31 | 32 | \subsection*{上下界网络流} 33 | 有上下界网络流,求可行流部分,增广的流量不是实际流量。若要求实际流量应该强算一遍源点出去的流量。\\ 34 | 求最小下届网络流:\\ 35 | 方法一:加 t-s 的无穷大流,求可行流,然后把边反向后(减去下届网络流),在残留网络中从汇到源做最大流。\\ 36 | 方法二:在求可行流的时候,不加从汇到源的无穷大边,得到最大流 X, 加上从汇到源无穷大边后,再求最大流得到 Y。那么 Y 即是答案最小下界网络流。\\ 37 | 原因:感觉上是在第一遍已经把内部都消耗光了,第二遍是必须的流量。 38 | 39 | \subsection*{平面图定理} 40 | 平面图一定存在一个度小于等于 5 的点,且可以四染色\\ 41 | ( 欧拉公式 ) 设 G 是连通的平面图,n , m, r 分别是其顶点数、边数和面数,n-m+r=2\\ 42 | 极大平面图 m≤3n-6 43 | 44 | \subsection*{Fibonacci相关结论} 45 | $gcd(2^a-1,2^b-1)=2^{gcd(a,b)}-1$\\ 46 | gcd(F[n],F[m])=F[gcd(n,m)] (牛书,P228)\\ 47 | Fibonacci 质数(和前面所有的 Fibonacci 数互质)\\ 48 | (大多已经是质数了,可能有 BUG 吧,不确定)\\ 49 | 定理:如果 a 是 b 的倍数,那么 Fa 是 Fb 的倍数。\\ 50 | 51 | \subsection*{二次剩余} 52 | p 为奇素数,若(a,p)=1, a 为 p 的二次剩余必要充分条件为 $a^((p-1)/2) \mod p=1$.(否则为 p-1)\\ 53 | p 为奇素数, $x^b= a(\mod p)$,a 为 p 的 b 次剩余的必要充分条件为若 $a^{(p-1)/ (p-1, b)}$ mod p=1. 54 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/极大团搜索.tex: -------------------------------------------------------------------------------- 1 | Int g[][]为图的邻接矩阵。\\ 2 | MC(V)表示点集V的最大团\\ 3 | 令Si={vi, vi+1, ..., vn}, mc[i]表示MC(Si)\\ 4 | 倒着算mc[i],那么显然MC(V)=mc[1]\\ 5 | 此外有mc[i]=mc[i+1] or mc[i]=mc[i+1]+1\\ 6 | \begin{lstlisting} 7 | void init(){ 8 | int i, j; 9 | for (i=1; i<=n; ++i) for (j=1; j<=n; ++j) scanf("%d", &g[i][j]); 10 | } 11 | void dfs(int size){ 12 | int i, j, k; 13 | if (len[size]==0) { 14 | if (size>ans) { 15 | ans=size; found=true; 16 | } 17 | return; 18 | } 19 | for (k=0; k0){ 18 | for (i=k; i<=ce[size]; ++i) if (!g[list[size][t]][list[size][i]]) 19 | break; 20 | swap(list[size][k], list[size][i]); 21 | } 22 | i=list[size][k]; 23 | ne[size+1]=ce[size+1]=0; 24 | for (j=1; j 2 | using namespace std; 3 | 4 | int whatday(int d, int m, int y) 5 | { 6 | int ans; 7 | if (m == 1 || m == 2) { 8 | m += 12; y --; 9 | } 10 | if ((y < 1752) || (y == 1752 && m < 9) || (y == 1752 && m == 9 && d < 3)) 11 | ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 + 5) % 7; 12 | else ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; 13 | return ans; 14 | } 15 | 16 | int main() 17 | { 18 | cout << whatday(30, 10, 2013) << endl; 19 | } 20 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/求某年某月某日星期几/求某年某月某日星期几.tex: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int whatday(int d, int m, int y) 5 | { 6 | int ans; 7 | if (m == 1 || m == 2) { 8 | m += 12; y --; 9 | } 10 | if ((y < 1752) || (y == 1752 && m < 9) || (y == 1752 && m == 9 && d < 3)) 11 | ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 + 5) % 7; 12 | else ans = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; 13 | return ans; 14 | } 15 | 16 | int main() 17 | { 18 | cout << whatday(30, 10, 2013) << endl; 19 | } 20 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/注意.tex: -------------------------------------------------------------------------------- 1 | \begin{enumerate} 2 | \item 注意舍入方式(0.5的舍入方向),防止输出-0 3 | \item 几何题注意多测试不对称数据 4 | \item 整数几何注意避免出界 5 | \item 符点几何注意EPS的使用 6 | \item 公式化简后再代入 7 | \item atan2(0,0)=0, atan2的值域为[-$\pi$, $\pi$] 8 | \item 使用acos, asin, sqrt 等函数时,注意定义域 9 | \end{enumerate} 10 | 11 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/牛顿迭代开根号.tex: -------------------------------------------------------------------------------- 1 | 速度慢,精度有保证 2 | \begin{lstlisting} 3 | typedef unsigned long long ull; 4 | ull sqrtll(ull n) 5 | { 6 | if (n == 0) return 0; 7 | ull x = 1ull << ((63 - __builtin_clzll(n)) >> 1); 8 | ull xx = -1; 9 | for( ; ; ) { 10 | ull nx = (x + n / x) >> 1; 11 | if (nx == xx) 12 | return min(x, nx); 13 | xx = x; 14 | x = nx; 15 | } 16 | } 17 | \end{lstlisting} 18 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/牛顿迭代开根号/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef unsigned long long ull; 8 | 9 | ull sqrtll(ull n) 10 | { 11 | if (n == 0) return 0; 12 | ull x = 1ull << ((63 - __builtin_clzll(n)) >> 1); 13 | ull xx = -1; 14 | for( ; ; ) { 15 | ull nx = (x + n / x) >> 1; 16 | if (nx == xx) 17 | return min(x, nx); 18 | xx = x; 19 | x = nx; 20 | } 21 | } 22 | 23 | int main() 24 | { 25 | srand(time(0)); 26 | ull a, b, x; 27 | a = rand(); 28 | b = rand(); 29 | int flag = true; 30 | for( ; ; ) { 31 | x = x * a + b; 32 | ull r1 = sqrtll(x); 33 | ull r2 = (ull)(sqrt(x) + 0.5); 34 | if (r1 != r2) { 35 | flag = false; 36 | cout << x << ' ' << r1 << ' ' << r1 * r1 << ' ' << r2 << ' ' << r2 * r2 << endl; 37 | break; 38 | } 39 | } 40 | if (flag) cout << "!!" << endl; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/牛顿迭代开根号/牛顿迭代开根号.tex: -------------------------------------------------------------------------------- 1 | 速度慢,精度有保证 2 | \begin{lstlisting} 3 | typedef unsigned long long ull; 4 | ull sqrtll(ull n) 5 | { 6 | if (n == 0) return 0; 7 | ull x = 1ull << ((63 - __builtin_clzll(n)) >> 1); 8 | ull xx = -1; 9 | for( ; ; ) { 10 | ull nx = (x + n / x) >> 1; 11 | if (nx == xx) 12 | return min(x, nx); 13 | xx = x; 14 | x = nx; 15 | } 16 | } 17 | \end{lstlisting} 18 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/球面.tex: -------------------------------------------------------------------------------- 1 | 计算圆心角lat表示纬度,$-90\leq w\leq 90$,lng表示经度 \\ 2 | 返回两点所在大圆劣弧对应圆心角,$0\leq angle \leq \pi$ 3 | \begin{lstlisting} 4 | double angle(double lng1,double lat1,double lng2,double lat2) { 5 | double dlng = abs(lng1 - lng2) * PI / 180; 6 | while(dlng >= PI + PI) dlng -= PI + PI; 7 | if (dlng > PI) dlng = PI + PI - dlng; 8 | lat1 *= PI / 180, lat2 *= PI / 180; 9 | return acos(cos(lat1) * cos(lat2) * cos(dlng) + sin(lat1) * sin(lat2)); 10 | } 11 | \end{lstlisting} 12 | 13 | 计算直线距离,$r$为球半径 14 | \begin{lstlisting} 15 | double line_dist(double r,double lng1,double lat1,double lng2,double lat2) { 16 | double dlng = abs(lng1 - lng2) * PI / 180; 17 | while(dlng >= PI + PI) dlng -= PI + PI; 18 | if (dlng > PI) dlng = PI + PI - dlng; 19 | lat1 *= PI / 180, lat2 *= PI / 180; 20 | return r * sqrt(2 - 2 * (cos(lat1) * cos(lat2) * cos(dlng) + sin(lat1) * sin(lat2))); 21 | } 22 | \end{lstlisting} 23 | 24 | 计算球面距离,$r$为球半径 25 | \begin{lstlisting} 26 | inline double sphere_dist(double r,double lng1,double lat1,double lng2,double lat2){ 27 | return r * angle(lng1, lat1, lng2, lat2); 28 | } 29 | \end{lstlisting} 30 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/直线凸包.tex~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/直线凸包.tex~ -------------------------------------------------------------------------------- /SCL-collection/SuperNova/线性递推.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | // given first m a[i] and coef c[i] (0-based), 3 | // calc a[n] mod p in O(m*m*log(n)). 4 | // a[n] = sum(c[m-i]*a[n-i]), i = 1...m 5 | // i.e. a[m] = sum(c[i]*a[i]), i = 0...m-1 6 | int linear_recurrence(LL n, int m, int a[], int c[], int p) { 7 | LL v[M] = {1 % p}, u[M<<1], msk = !!n; 8 | for(LL i = n; i > 1; i >>= 1) msk <<= 1; 9 | for(LL x = 0; msk; msk >>= 1, x <<= 1) { 10 | fill_n(u, m<<1, 0); 11 | int b = !!(n & msk); x |= b; 12 | if(x < m) u[x] = 1 % p; 13 | else { 14 | for(int i = 0; i < m; ++i) 15 | for(int j = 0, t = i+b; j < m; ++j, ++t) 16 | u[t] = (u[t]+v[i]*v[j]) % p; 17 | for(int i = (m<<1)-1; i >= m; --i) 18 | for(int j = 0, t = i-m; j < m; ++j, ++t) 19 | u[t] = (u[t]+c[j]*u[i]) % p; 20 | } 21 | copy(u, u+m, v); 22 | } 23 | int an = 0; 24 | for(int i = 0; i < m; ++i) an = (an+v[i]*a[i]) % p; 25 | return an; 26 | } 27 | \end{lstlisting} 28 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/线性递推.tex~: -------------------------------------------------------------------------------- 1 | // given first m a[i] and coef c[i] (0-based), 2 | // calc a[n] mod p in O(m*m*log(n)). 3 | // a[n] = sum(c[m-i]*a[n-i]), i = 1...m 4 | // i.e. a[m] = sum(c[i]*a[i]), i = 0...m-1 5 | int linear_recurrence(LL n, int m, int a[], int c[], int p) { 6 | LL v[M] = {1 % p}, u[M<<1], msk = !!n; 7 | for(LL i = n; i > 1; i >>= 1) msk <<= 1; 8 | for(LL x = 0; msk; msk >>= 1, x <<= 1) { 9 | fill_n(u, m<<1, 0); 10 | int b = !!(n & msk); x |= b; 11 | if(x < m) u[x] = 1 % p; 12 | else { 13 | for(int i = 0; i < m; ++i) 14 | for(int j = 0, t = i+b; j < m; ++j, ++t) 15 | u[t] = (u[t]+v[i]*v[j]) % p; 16 | for(int i = (m<<1)-1; i >= m; --i) 17 | for(int j = 0, t = i-m; j < m; ++j, ++t) 18 | u[t] = (u[t]+c[j]*u[i]) % p; 19 | } 20 | copy(u, u+m, v); 21 | } 22 | int an = 0; 23 | for(int i = 0; i < m; ++i) an = (an+v[i]*a[i]) % p; 24 | return an; 25 | } 26 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/线性递推/a.cpp: -------------------------------------------------------------------------------- 1 | // given first m a[i] and coef c[i] (0-based), 2 | // calc a[n] mod p in O(m*m*log(n)). 3 | // a[n] = sum(c[m-i]*a[n-i]), i = 1...m 4 | // i.e. a[m] = sum(c[i]*a[i]), i = 0...m-1 5 | int linear_recurrence(LL n, int m, int a[], int c[], int p) { 6 | LL v[M] = {1 % p}, u[M<<1], msk = !!n; 7 | for(LL i = n; i > 1; i >>= 1) msk <<= 1; 8 | for(LL x = 0; msk; msk >>= 1, x <<= 1) { 9 | fill_n(u, m<<1, 0); 10 | int b = !!(n & msk); x |= b; 11 | if(x < m) u[x] = 1 % p; 12 | else { 13 | for(int i = 0; i < m; ++i) 14 | for(int j = 0, t = i+b; j < m; ++j, ++t) 15 | u[t] = (u[t]+v[i]*v[j]) % p; 16 | for(int i = (m<<1)-1; i >= m; --i) 17 | for(int j = 0, t = i-m; j < m; ++j, ++t) 18 | u[t] = (u[t]+c[j]*u[i]) % p; 19 | } 20 | copy(u, u+m, v); 21 | } 22 | int an = 0; 23 | for(int i = 0; i < m; ++i) an = (an+v[i]*a[i]) % p; 24 | return an; 25 | } 26 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/线性递推/x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/SuperNova/线性递推/x -------------------------------------------------------------------------------- /SCL-collection/SuperNova/线性递推/x.in: -------------------------------------------------------------------------------- 1 | 3 2 | 2 1 2 3 | 4 1 2 3 4 4 | 5 5 | 2 1 2 6 | 4 1 2 3 4 7 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/长方体表面两点最短距离.tex: -------------------------------------------------------------------------------- 1 | 返回最短距离的平方 2 | \begin{lstlisting} 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int r; 10 | void turn(int i, int j, int x, int y, int z, int x0, int y0, int L, int W, int H) 11 | { 12 | if (z == 0) { 13 | int R = x * x + y * y; 14 | if (R < r) r = R; 15 | } else { 16 | if (i >= 0 && i < 2) 17 | turn(i + 1, j, x0 + L + z, y, x0 + L - x, x0 + L, y0, H, W, L); 18 | if (j >= 0 && j < 2) 19 | turn(i, j + 1, x, y0 + W + z, y0 + W - y, x0, y0 + W, L, H, W); 20 | if (i <= 0 && i > -2) 21 | turn(i - 1, j, x0 - z, y, x - x0, x0 - H, y0, H, W, L); 22 | if (j <= 0 && j > -2) 23 | turn(i, j - 1, x, y0 - z, y - y0, x0, y0 - H, L, H, W); 24 | } 25 | } 26 | 27 | int main() 28 | { 29 | int L, H, W, x1, y1, z1, x2, y2, z2; 30 | cin >> L >> W >> H >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 31 | if (z1 != 0 && z1 != H) { 32 | if (y1 == 0 || y1 == W) 33 | swap(y1, z1), swap(y2, z2), swap(W, H); 34 | else 35 | swap(x1, z1), swap(x2, z2), swap(L, H); 36 | } 37 | if (z1 == H) z1 = 0, z2 = H - z2; 38 | r = 0x3fffffff; 39 | turn(0, 0, x2 - x1, y2 - y1, z2, -x1, -y1, L, W, H); 40 | cout << r << endl; 41 | return 0; 42 | } 43 | \end{lstlisting} 44 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/长方体表面两点最短距离/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int r; 8 | void turn(int i, int j, int x, int y, int z, int x0, int y0, int L, int W, int H) 9 | { 10 | if (z == 0) { 11 | int R = x * x + y * y; 12 | if (R < r) r = R; 13 | } else { 14 | if (i >= 0 && i < 2) 15 | turn(i + 1, j, x0 + L + z, y, x0 + L - x, x0 + L, y0, H, W, L); 16 | if (j >= 0 && j < 2) 17 | turn(i, j + 1, x, y0 + W + z, y0 + W - y, x0, y0 + W, L, H, W); 18 | if (i <= 0 && i > -2) 19 | turn(i - 1, j, x0 - z, y, x - x0, x0 - H, y0, H, W, L); 20 | if (j <= 0 && j > -2) 21 | turn(i, j - 1, x, y0 - z, y - y0, x0, y0 - H, L, H, W); 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | int L, H, W, x1, y1, z1, x2, y2, z2; 28 | cin >> L >> W >> H >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 29 | if (z1 != 0 && z1 != H) { 30 | if (y1 == 0 || y1 == W) 31 | swap(y1, z1), swap(y2, z2), swap(W, H); 32 | else 33 | swap(x1, z1), swap(x2, z2), swap(L, H); 34 | } 35 | if (z1 == H) z1 = 0, z2 = H - z2; 36 | r = 0x3fffffff; 37 | turn(0, 0, x2 - x1, y2 - y1, z2, -x1, -y1, L, W, H); 38 | cout << r << endl; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/长方体表面两点最短距离/a.in: -------------------------------------------------------------------------------- 1 | 3 2 2 0 0 0 3 2 2 2 | -------------------------------------------------------------------------------- /SCL-collection/SuperNova/长方体表面两点最短距离/长方体表面两点最短距离.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int r; 9 | void turn(int i, int j, int x, int y, int z, int x0, int y0, int L, int W, int H) 10 | { 11 | if (z == 0) { 12 | int R = x * x + y * y; 13 | if (R < r) r = R; 14 | } else { 15 | if (i >= 0 && i < 2) 16 | turn(i + 1, j, x0 + L + z, y, x0 + L - x, x0 + L, y0, H, W, L); 17 | if (j >= 0 && j < 2) 18 | turn(i, j + 1, x, y0 + W + z, y0 + W - y, x0, y0 + W, L, H, W); 19 | if (i <= 0 && i > -2) 20 | turn(i - 1, j, x0 - z, y, x - x0, x0 - H, y0, H, W, L); 21 | if (j <= 0 && j > -2) 22 | turn(i, j - 1, x, y0 - z, y - y0, x0, y0 - H, L, H, W); 23 | } 24 | } 25 | 26 | int main() 27 | { 28 | int L, H, W, x1, y1, z1, x2, y2, z2; 29 | cin >> L >> W >> H >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 30 | if (z1 != 0 && z1 != H) { 31 | if (y1 == 0 || y1 == W) 32 | swap(y1, z1), swap(y2, z2), swap(W, H); 33 | else 34 | swap(x1, z1), swap(x2, z2), swap(L, H); 35 | } 36 | if (z1 == H) z1 = 0, z2 = H - z2; 37 | r = 0x3fffffff; 38 | turn(0, 0, x2 - x1, y2 - y1, z2, -x1, -y1, L, W, H); 39 | cout << r << endl; 40 | return 0; 41 | } 42 | \end{lstlisting} 43 | -------------------------------------------------------------------------------- /SCL-collection/log: -------------------------------------------------------------------------------- 1 | 多边形与圆面积交 -------------------------------------------------------------------------------- /SCL-collection/template/ACM模板.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/ACM模板.pdf -------------------------------------------------------------------------------- /SCL-collection/template/SCL/Geo-convexcut.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector convexCut(const vector&ps, Point q1, Point q2) { 3 | vector qs; 4 | int n = ps.size(); 5 | for (int i = 0; i < n; ++i) { 6 | Point p1 = ps[i], p2 = ps[(i + 1) % n]; 7 | int d1 = crossOp(q1,q2,p1), d2 = crossOp(q1,q2,p2); 8 | if (d1 >= 0) 9 | qs.push_back(p1); 10 | if (d1 * d2 < 0) 11 | qs.push_back(isSS(p1, p2, q1, q2)); 12 | } 13 | return qs; 14 | } 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/Geo-convexhull.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | vector convexHull(vector ps) { 3 | int n = ps.size(); 4 | if (n <= 1) 5 | return ps; 6 | sort(ps.begin(), ps.end()); 7 | vector qs; 8 | for (int i = 0; i < n; qs.push_back(ps[i++])) { 9 | while (qs.size() > 1 && crossOp(qs[qs.size()-2],qs.back(),ps[i]) <= 0) 10 | qs.pop_back(); 11 | } 12 | for (int i = n - 2, t = qs.size(); i >= 0; qs.push_back(ps[i--])) { 13 | while (qs.size() > t && crossOp(qs[qs.size()-2],qs.back(),ps[i]) <= 0) 14 | qs.pop_back(); 15 | } 16 | qs.pop_back(); 17 | return qs; 18 | } 19 | \end{lstlisting} 20 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/Geo-diameter.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | double convexDiameter(const vector&ps) { 3 | int n = ps.size(); 4 | int is = 0, js = 0; 5 | for (int i = 1; i < n; ++i) { 6 | if (ps[i].x > ps[is].x) 7 | is = i; 8 | if (ps[i].x < ps[js].x) 9 | js = i; 10 | } 11 | double maxd = ps[is].distTo(ps[js]); 12 | int i = is, j = js; 13 | do { 14 | if ((ps[(i + 1) % n] - ps[i]).det(ps[(j + 1) % n] - ps[j]) >= 0) 15 | (++j) %= n; 16 | else 17 | (++i) %= n; 18 | maxd = max(maxd, ps[i].distTo(ps[j])); 19 | } while (i != is || j != js); 20 | return maxd; 21 | } 22 | \end{lstlisting} 23 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/KM.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const int MAX_N = 200 + 10; 3 | const int INF = 1000000000; 4 | 5 | int N, flag; 6 | int w[MAX_N][MAX_N]; 7 | int fx[MAX_N], fy[MAX_N], lx[MAX_N], ly[MAX_N], slk[MAX_N], mat[MAX_N]; 8 | 9 | int DFS(int x) { 10 | fx[x] = flag; 11 | for(int i = 1; i <= N; ++ i) 12 | if (lx[x] + ly[i] != w[x][i]) 13 | slk[i] = min(slk[i], lx[x] + ly[i] - w[x][i]); 14 | else if (fy[i] != flag) { 15 | fy[i] = flag; 16 | if (mat[i] < 0 || DFS(mat[i])) { 17 | mat[i] = x; 18 | return true; 19 | } 20 | } 21 | return false; 22 | } 23 | 24 | int KM() { 25 | for(int i = 1; i <= N; ++ i) { 26 | mat[i] = -1; 27 | fx[i] = 0; fy[i] = 0; 28 | ly[i] = 0; lx[i] = -INF; 29 | for(int j = 1; j <= N; ++ j) 30 | lx[i] = max(lx[i], w[i][j]); 31 | } 32 | for(int now = 1; now <= N; ++ now) { 33 | ++ flag; for(int i = 1; i <= N; ++ i) slk[i] = INF; 34 | while (! DFS(now)) { 35 | int p(INF); for(int i = 1; i <= N; ++ i) 36 | if (fy[i] != flag) p = min(p, slk[i]); 37 | for(int i = 1; i <= N; ++ i) { 38 | if (fx[i] == flag) lx[i] -= p; 39 | if (fy[i] == flag) ly[i] += p; 40 | slk[i] = INF; 41 | } 42 | ++ flag; 43 | } 44 | } 45 | long long ans = 0; 46 | for(int i = 1; i <= N; ++ i) ans += lx[i], ans += ly[i]; 47 | return ans; 48 | } 49 | \end{lstlisting} 50 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/LCT.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Node 3 | { 4 | Node *ch[2], *p; 5 | int isroot; 6 | bool dir(); 7 | void set(Node*, bool); 8 | void update(); 9 | void relax(); 10 | } *null; 11 | 12 | void rot(Node *t) 13 | { 14 | Node *p = t->p; bool d = t->dir(); 15 | p->relax(); t->relax(); 16 | p->set(t->ch[! d], d); 17 | if (p->isroot) t->p = p->p, swap(p->isroot, t->isroot); 18 | else p->p->set(t, p->dir()); 19 | t->set(p, ! d); 20 | p->update(); 21 | } 22 | 23 | void Splay(Node *t) 24 | { 25 | for(t->relax(); ! t->isroot; ) { 26 | if (t->p->isroot) rot(t); 27 | else t->dir() == t->p->dir() ? (rot(t->p), rot(t)) : (rot(t), rot(t)); 28 | } 29 | t->update(); 30 | } 31 | 32 | void Access(Node *t) 33 | { 34 | for(Node *s = null; t != null; s = t, t = t->p) { 35 | Splay(t); 36 | t->ch[1]->isroot = true; 37 | s->isroot = false; 38 | t->ch[1] = s; 39 | t->update(); 40 | } 41 | } 42 | bool Node::dir() 43 | { 44 | return this == p->ch[1]; 45 | } 46 | void Node::set(Node *t, bool _d) 47 | { 48 | ch[_d] = t; t->p = this; 49 | } 50 | void Node::Update() 51 | { 52 | 53 | } 54 | void Node::Relax() 55 | { 56 | if (this == Null) return; 57 | 58 | } 59 | \end{lstlisting} 60 | 61 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/SCC.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int totID, totCol; 3 | int col[MAX_N], low[MAX_N], dfn[MAX_N]; 4 | int top, stack[MAX_N], instack[MAX_N]; 5 | 6 | int tarjan(int u) 7 | { 8 | low[u] = dfn[u] = ++ totID; 9 | instack[u] = true; stack[++ top] = u; 10 | 11 | int v; 12 | foreach(it, adj[u]) { 13 | v = it->first; 14 | if (dfn[v] == -1) 15 | low[u] = min(low[u], tarjan(v)); 16 | else if (instack[v]) 17 | low[u] = min(low[u], dfn[v]); 18 | } 19 | 20 | if (low[u] == dfn[u]) { 21 | do { 22 | v = stack[top --]; 23 | instack[v] = false; 24 | col[v] = totCol; 25 | } while(v != u); 26 | ++ totCol; 27 | } 28 | return low[u]; 29 | } 30 | 31 | void solve() 32 | { 33 | totID = totCol = top = 0; 34 | fill(dfn, dfn + N, 0); 35 | for(int i = 0; i < N; ++ i) 36 | if (! dfn[i]) 37 | tarjan(i); 38 | } 39 | \end{lstlisting} 40 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/acautomaton.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | 3 | struct acNode 4 | { 5 | int id; 6 | acNode *ch[26], *fail; 7 | } *totNode, *root, nodePool[MAX_V]; 8 | 9 | acNode* newNode() 10 | { 11 | acNode *now = totNode ++; 12 | now->id = 0; now->fail = 0; 13 | memset(now->ch, 0, sizeof now->ch); 14 | return now; 15 | } 16 | 17 | void acInsert(char *c, int id) 18 | { 19 | acNode *cur = root; 20 | while (*c) { 21 | int p = *c - 'A'; //change the index 22 | if (! cur->ch[p]) cur->ch[p] = newNode(); 23 | cur = cur->ch[p]; 24 | ++ c; 25 | } 26 | cur->id = id; 27 | } 28 | 29 | void getFail() 30 | { 31 | acNode *cur; 32 | queue Q; 33 | for(int i = 0; i < 26; ++ i) 34 | if (root->ch[i]) { 35 | root->ch[i]->fail = root; 36 | Q.push(root->ch[i]); 37 | } else root->ch[i] = root; 38 | while (! Q.empty()) { 39 | cur = Q.front(); Q.pop(); 40 | for(int i = 0; i < 26; ++ i) 41 | if (cur->ch[i]) { 42 | cur->ch[i]->fail = cur->fail->ch[i]; 43 | Q.push(cur->ch[i]); 44 | } else cur->ch[i] = cur->fail->ch[i]; 45 | } 46 | } 47 | \end{lstlisting} 48 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/binary-heap.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const int MAX_V = 100000 + 10; 3 | struct Heap 4 | { 5 | int tot; 6 | int a[MAX_V], h[MAX_V], ind[MAX_V]; 7 | void exchange(int i, int j) { 8 | swap(h[i], h[j]); 9 | swap(ind[h[i]], ind[h[j]]); 10 | } 11 | inline int val(int x) { 12 | return a[h[x]]; 13 | } 14 | void fixUp(int x) { 15 | if (x / 2 && val(x / 2) < val(x)) 16 | exchange(x, x / 2), fixUp(x / 2); 17 | } 18 | void fixDown(int x) { 19 | int p = x * 2; if (p > tot) return; 20 | if (p < tot && val(p + 1) > val(p)) ++ p; 21 | if (val(p) > val(x)) 22 | exchange(p, x), fixDown(p); 23 | } 24 | void Update(int i, int x) { 25 | a[i] = x; 26 | fixUp(ind[i]); 27 | fixDown(ind[i]); 28 | } 29 | int top() { 30 | return h[1]; 31 | } 32 | void pop() { 33 | exchange(1, tot); 34 | -- tot; 35 | fixDown(1); 36 | } 37 | void insert(int i, int x) { 38 | ++ tot; 39 | h[tot] = i; 40 | ind[i] = tot; 41 | a[i] = x; 42 | fixUp(tot); 43 | } 44 | } H; 45 | \end{lstlisting} 46 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/crt.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | LL x, y; 3 | void exGcd(LL a, LL b) 4 | { 5 | if (b == 0) { 6 | x = 1; 7 | y = 0; 8 | return; 9 | } 10 | exGcd(b, a % b); 11 | LL k = y; 12 | y = x - a / b * y; 13 | x = k; 14 | } 15 | 16 | LL inversion(LL a, LL b) 17 | { 18 | exGcd(a, b); 19 | return (x % b + b) % b; 20 | } 21 | 22 | LL CRT(vector m, vector a) 23 | { 24 | int N = m.size(); 25 | LL M = 1, ret = 0; 26 | for(int i = 0; i < N; ++ i) 27 | M *= m[i]; 28 | 29 | for(int i = 0; i < N; ++ i) { 30 | ret = (ret + (M / m[i]) * a[i] % M * inversion(M / m[i], m[i])) % M; 31 | } 32 | return ret; 33 | } 34 | \end{lstlisting} 35 | 36 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/decomposition.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Tree() 3 | { 4 | 5 | }; 6 | 7 | int father[MAX_N], size[MAX_N], depth[MAX_N]; 8 | int bfsOrd[MAX_N], pathId[MAX_N], ordInPath[MAX_N], sqn[MAX_N]; 9 | Tree *root[MAX_N]; 10 | 11 | void doBfs(int s) 12 | { 13 | int *que = bfsOrd; 14 | int qh = 0, qt = 0; 15 | father[s] = -1; depth[s] = 0; 16 | 17 | for(que[qt ++] = s; qh < qt; ) { 18 | int u = que[qh ++]; 19 | foreach(iter, adj[u]) { 20 | int v = *iter; 21 | if (v == father[u]) 22 | continue; 23 | father[v] = u; 24 | depth[v] = depth[u] + 1; 25 | que[qt ++] = v; 26 | } 27 | } 28 | } 29 | 30 | void doSplit() 31 | { 32 | for(int i = N - 1; i >= 0; -- i) { 33 | int u = bfsOrd[i]; 34 | size[u] = 1; 35 | foreach(iter, adj[u]) { 36 | int v = *iter; 37 | if (v == father[u]) 38 | continue; 39 | size[u] += size[v]; 40 | } 41 | } 42 | 43 | memset(pathId, -1, sizeof pathId); 44 | for(int i = 0; i < N; ++ i) { 45 | int top = bfsOrd[i]; 46 | if (pathId[top] != -1) 47 | continue; 48 | 49 | int cnt = 0; 50 | for(int u = top; u != -1; ) { 51 | sqn[cnt] = val[u]; 52 | ordInPath[u] = cnt; 53 | pathId[u] = top; 54 | ++ cnt; 55 | 56 | int next = -1; 57 | foreach(iter, adj[u]) { 58 | int v = *iter; 59 | if (v == father[u]) 60 | continue; 61 | if (next < 0 || size[next] < size[v]) 62 | next = v; 63 | } 64 | u = next; 65 | } 66 | 67 | root[top] = new Tree(0, cnt, sqn); 68 | } 69 | } 70 | 71 | void prepare() 72 | { 73 | doBfs(0); 74 | doSplit(); 75 | } 76 | 77 | \end{lstlisting} 78 | 79 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/dijkstra.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int used[MAX_N], dis[MAX_N]; 3 | void dijstra(int s) { 4 | fill(dis, dis + N, INF); dis[s] = 0; 5 | priority_queue > que; 6 | que.push(make_pair(-dis[s], s)); 7 | while (!que.empty()) { 8 | int u = que.top().second; que.pop(); 9 | if (used[u]) continue; 10 | used[u] = true; 11 | foreach(e, E[u]) 12 | if (dis[u] + e->w < dis[e->t]) { 13 | dis[e->t] = dis[u] + e->w; 14 | que.push(make_pair(-dis[e->t], e->t)); 15 | } 16 | } 17 | } 18 | \end{lstlisting} 19 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/leftist-tree.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Node 3 | { 4 | int dis, val; 5 | Node *ch[2]; 6 | } *null; 7 | 8 | Node* merge(Node *u, Node *v) 9 | { 10 | if (u == null) return v; 11 | if (v == null) return u; 12 | if (u->val < v->val) swap(u, v); 13 | u->ch[1] = merge(u->ch[1], v); 14 | if (u->ch[1]->dis > u->ch[0]->dis) 15 | swap(u->ch[1], u->ch[0]); 16 | u->dis = u->ch[1]->dis + 1; 17 | return u; 18 | } 19 | 20 | Node* newNode(int w) 21 | { 22 | Node *t = totNode ++; 23 | t->ch[0] = t->ch[1] = null; 24 | t->val = w; t->dis = 0; 25 | return t; 26 | } 27 | \end{lstlisting} 28 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/SCL/main.pdf -------------------------------------------------------------------------------- /SCL-collection/template/SCL/main.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/SCL/main.synctex.gz -------------------------------------------------------------------------------- /SCL-collection/template/SCL/manacher.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void palindrome(char cs[], int len[], int n) { 3 | for (int i = 0; i < n * 2; ++i) { 4 | len[i] = 0; 5 | } 6 | for (int i = 0, j = 0, k; i < n * 2; i += k, j = max(j - k, 0)) { 7 | while (i - j >= 0 && i + j + 1 < n * 2 && cs[(i - j) / 2] == cs[(i + j + 1) / 2]) 8 | j++; 9 | len[i] = j; 10 | for (k = 1; i - k >= 0 && j - k >= 0 && len[i - k] != j - k; k++) { 11 | len[i + k] = min(len[i - k], j - k); 12 | } 13 | } 14 | } 15 | \end{lstlisting} 16 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/maxflow.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Edge 3 | { 4 | int t, c; 5 | Edge *n, *r; 6 | } *E[MAX_V], edges[MAX_M], *totEdge; 7 | 8 | Edge* makeEdge(int s, int t, int c) 9 | { 10 | Edge *e = totEdge ++; 11 | e->t = t; e->c = c; e->n = E[s]; 12 | return E[s] = e; 13 | } 14 | 15 | void addEdge(int s, int t, int c) 16 | { 17 | Edge *p = makeEdge(s, t, c), *q = makeEdge(t, s, 0); 18 | p->r = q; q->r = p; 19 | } 20 | 21 | int maxflow() 22 | { 23 | static int cnt [MAX_V]; 24 | static int h [MAX_V]; 25 | static int que [MAX_V]; 26 | static int aug [MAX_V]; 27 | static Edge *cur [MAX_V]; 28 | static Edge *prev [MAX_V]; 29 | fill(h, h + cntN, cntN); 30 | memset(cnt, 0, sizeof cnt); 31 | int qt = 0, qh = 0; h[T] = 0; 32 | for(que[qt ++] = T; qh < qt; ) { 33 | int u = que[qh ++]; 34 | ++ cnt[h[u]]; 35 | for(Edge *e = E[u]; e; e = e->n) 36 | if (e->r->c && h[e->t] == cntN) { 37 | h[e->t] = h[u] + 1; 38 | que[qt ++] = e->t; 39 | } 40 | } 41 | memcpy(cur, E, sizeof E); 42 | aug[S] = INF; Edge *e; 43 | int flow = 0, u = S; 44 | while (h[S] < cntN) { 45 | for(e = cur[u]; e; e = e->n) 46 | if (e->c && h[e->t] + 1 == h[u]) 47 | break; 48 | if (e) { 49 | int v = e->t; 50 | cur[u] = prev[v] = e; 51 | aug[v] = min(aug[u], e->c); 52 | if ((u = v) == T) { 53 | int by = aug[T]; 54 | while (u != S) { 55 | Edge *p = prev[u]; 56 | p->c -= by; 57 | p->r->c += by; 58 | u = p->r->t; 59 | } 60 | flow += by; 61 | } 62 | } else { 63 | if (!-- cnt[h[u]]) return flow; 64 | h[u] = cntN; 65 | for(e = E[u]; e; e = e->n) 66 | if (e->c && h[u] > h[e->t] + 1) 67 | h[u] = h[e->t] + 1, cur[u] = e; 68 | ++ cnt[h[u]]; 69 | if (u != S) u = prev[u]->r->t; 70 | } 71 | } 72 | return flow; 73 | } 74 | \end{lstlisting} 75 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/mincostflow.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | int flow, cost; 3 | 4 | struct Edge 5 | { 6 | int t, c, w; 7 | Edge *n, *r; 8 | } *totEdge, edges[MAX_M], *E[MAX_V]; 9 | 10 | Edge* makeEdge(int s, int t, int c, int w) 11 | { 12 | Edge *e = totEdge ++; 13 | e->t = t; e->c = c; e->w = w; e->n = E[s]; 14 | return E[s] = e; 15 | } 16 | 17 | void addEdge(int s, int t, int c, int w) 18 | { 19 | Edge *st = makeEdge(s, t, c, w), *ts = makeEdge(t, s, 0, -w); 20 | st->r = ts; ts->r = st; 21 | } 22 | 23 | int SPFA() 24 | { 25 | static int que[MAX_V]; 26 | static int aug[MAX_V]; 27 | static int in[MAX_V]; 28 | static int dist[MAX_V]; 29 | static Edge *prev[MAX_V]; 30 | int qh = 0, qt = 0; 31 | 32 | int u, v; 33 | fill(dist, dist + cntN, INF); dist[S] = 0; 34 | fill(in, in + cntN, 0); in[S] = true; 35 | que[qt ++] = S; aug[S] = INF; 36 | for( ; qh != qt; ) { 37 | u = que[qh]; qh = (qh + 1) % MAX_N; 38 | for(Edge *e = E[u]; e; e = e->n) { 39 | if (! e->c) continue; 40 | v = e->t; 41 | if (dist[v] > dist[u] + e->w) { 42 | dist[v] = dist[u] + e->w; 43 | aug[v] = min(aug[u], e->c); 44 | prev[v] = e; 45 | if (! in[v]) { 46 | in[v] = true; 47 | if (qh != qt && dist[v] <= dist[que[qh]]) { 48 | qh = (qh - 1 + MAX_N) % MAX_N; 49 | que[qh] = v; 50 | } else { 51 | que[qt] = v; 52 | qt = (qt + 1) % MAX_N; 53 | } 54 | } 55 | } 56 | } 57 | in[u] = false; 58 | } 59 | 60 | if (dist[T] == INF) return false; 61 | cost += dist[T] * aug[T]; 62 | flow += aug[T]; 63 | for(u = T; u != S; ) { 64 | prev[u]->c -= aug[T]; 65 | prev[u]->r->c += aug[T]; 66 | u = prev[u]->r->t; 67 | } 68 | return true; 69 | } 70 | 71 | int minCostFlow() 72 | { 73 | flow = cost = 0; 74 | while(SPFA()); 75 | return cost; 76 | } 77 | \end{lstlisting} 78 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/rho.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | typedef long long LL; 3 | 4 | LL modMul(LL a, LL b, LL P) 5 | { 6 | LL ret = 0; 7 | for( ; a; a >>= 1) { 8 | if (a & 1) { 9 | ret += b; 10 | if (ret >= P) ret -= P; 11 | } 12 | b <<= 1; 13 | if (b >= P) b -= P; 14 | } 15 | return ret; 16 | } 17 | 18 | LL modPow(LL a, LL u, LL P) 19 | { 20 | LL ret = 1; 21 | for( ; u; u >>= 1, a = modMul(a, a, P)) 22 | if (u & 1) ret = modMul(ret, a, P); 23 | return ret; 24 | } 25 | 26 | int millerRabin(LL N) 27 | { 28 | if (N == 2) return true; 29 | LL t = 0, u = N - 1, x, y, a; 30 | for( ; ! (u & 1); ++ t, u >>= 1) ; 31 | for(int k = 0; k < 10; ++ k) { 32 | a = rand() % (N - 2) + 2; 33 | x = modPow(a, u, N); 34 | for(int i = 0; i < t; ++ i, x = y) { 35 | y = modMul(x, x, N); 36 | if (y == 1 && x > 1 && x < N - 1) return false; 37 | } 38 | if (x != 1) return false; 39 | } 40 | return true; 41 | } 42 | 43 | LL gcd(LL a, LL b) 44 | { 45 | return ! b ? a : gcd(b, a % b); 46 | } 47 | 48 | LL pollardRho(LL N) 49 | { 50 | LL i = 1, x = rand() % N; 51 | LL y = x, k = 2, d = 1; 52 | do { 53 | d = gcd(x - y + N, N); 54 | if (d != 1 && d != N) return d; 55 | if (++ i == k) y = x, k <<= 1; 56 | x = (modMul(x, x, N) - 1 + N) % N; 57 | } while (y != x); 58 | return N; 59 | } 60 | 61 | void getFactor(LL N) 62 | { 63 | if (N < 2) return; 64 | if (millerRabin(N)) { 65 | //do some operations 66 | return; 67 | } 68 | LL x = pollardRho(N); 69 | getFactor(x); 70 | getFactor(N / x); 71 | } 72 | \end{lstlisting} 73 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/segment-tree.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct Tree 3 | { 4 | int l, r; 5 | Tree *ch[2]; 6 | Tree() {} 7 | Tree(int _l, int _r, int *sqn) { 8 | l = _l; r = _r; 9 | if (l + 1 == r) 10 | return; 11 | int mid = l + r >> 1; 12 | ch[0] = new Tree(l, mid, sqn); 13 | ch[1] = new Tree(mid, r, sqn); 14 | } 15 | 16 | void insert(int p, int x) { 17 | if (p < l || p >= r) 18 | return; 19 | //some operations 20 | if (l + 1 == r) 21 | return; 22 | ch[0]->insert(p, x); 23 | ch[1]->insert(p, x); 24 | } 25 | 26 | int query(int _l, int _r, int x) { 27 | if (_r <= l || _l >= r) 28 | return 0; 29 | if (_l <= l && _r >= r) 30 | // return information in [l, r) 31 | //merge ch[0]->query(_l, _r, x), ch[1]->query(_l, _r, x) and return 32 | } 33 | }; 34 | \end{lstlisting} 35 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/suffix-array.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | const int MAX_N = 1000000 + 10; 3 | 4 | int rank[MAX_N], height[MAX_N]; 5 | 6 | int cmp(int *x, int a, int b, int d) 7 | { 8 | return x[a] == x[b] && x[a + d] == x[b + d]; 9 | } 10 | 11 | void doubling(int *a, int N, int M) 12 | { 13 | static int sRank[MAX_N], tmpA[MAX_N], tmpB[MAX_N]; 14 | int *x = tmpA, *y = tmpB; 15 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 16 | for(int i = 0; i < N; ++ i) ++ sRank[x[i] = a[i]]; 17 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 18 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[i]]] = i; 19 | 20 | for(int d = 1, p = 0; p < N; M = p, d <<= 1) { 21 | p = 0; for(int i = N - d; i < N; ++ i) y[p ++] = i; 22 | for(int i = 0; i < N; ++ i) 23 | if (sa[i] >= d) y[p ++] = sa[i] - d; 24 | for(int i = 0; i < M; ++ i) sRank[i] = 0; 25 | for(int i = 0; i < N; ++ i) ++ sRank[x[i]]; 26 | for(int i = 1; i < M; ++ i) sRank[i] += sRank[i - 1]; 27 | for(int i = N - 1; i >= 0; -- i) sa[-- sRank[x[y[i]]]] = y[i]; 28 | swap(x, y); x[sa[0]] = 0; p = 1; 29 | for(int i = 1; i < N; ++ i) 30 | x[sa[i]] = cmp(y, sa[i], sa[i - 1], d) ? p - 1 : p ++; 31 | } 32 | } 33 | 34 | void calcHeight() 35 | { 36 | for(int i = 0; i < N; ++ i) rank[sa[i]] = i; 37 | int cur = 0; 38 | for(int i = 0; i < N; ++ i) 39 | if (rank[i]) { 40 | if (cur) cur --; 41 | for( ; a[i + cur] == a[sa[rank[i] - 1] + cur]; ++ cur); 42 | height[rank[i]] = cur; 43 | } 44 | } 45 | \end{lstlisting} 46 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/suffix-automaton.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | struct State 3 | { 4 | int val; 5 | State *suf, *go[26]; 6 | } *root, *last; 7 | 8 | State statePool[MAX_N], *curState; 9 | 10 | void extend(int w) 11 | { 12 | State *p = last, *np = curState ++; 13 | np->val = p->val + 1; 14 | for( ; p && ! p->go[w]; p = p->suf) 15 | p->go[w] = np; 16 | if (! p) 17 | np->suf = root; 18 | else { 19 | State *q = p->go[w]; 20 | if (q->val == p->val + 1) 21 | np->suf = q; 22 | else { 23 | State *nq = curState ++; 24 | nq->val = p->val + 1; 25 | memcpy(nq->go, q->go, sizeof q->go); 26 | nq->suf = q->suf; 27 | q->suf = np->suf = nq; 28 | for( ; p && p->go[w] == q; p = p->suf) 29 | p->go[w] = nq; 30 | } 31 | } 32 | last = np; 33 | } 34 | \end{lstlisting} 35 | 36 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/treap.tex: -------------------------------------------------------------------------------- 1 | 2 | \begin{lstlisting} 3 | struct Node *null; 4 | 5 | struct Node 6 | { 7 | int key, val, size; 8 | Node *ch[2]; 9 | Node() { 10 | key = INT_MAX; 11 | val = size = 0; 12 | } 13 | Node(int _val) { 14 | size = 1; 15 | val = _val; 16 | key = bigRand(); 17 | ch[0] = ch[1] = null; 18 | } 19 | int bigRand() { 20 | return rand() * RAND_MAX + rand(); 21 | } 22 | void update() { 23 | size = ch[0]->size + ch[1]->size + 1; 24 | } 25 | }; 26 | 27 | struct Treap 28 | { 29 | Node *root; 30 | Treap() { 31 | root = null; 32 | } 33 | void rot(Node *&t, int d) { 34 | Node *p = t->ch[d]; t->ch[d] = p->ch[! d]; p->ch[! d] = t; 35 | t->update(); p->update(); 36 | t = p; 37 | } 38 | 39 | void insert(Node *&t, int x) { 40 | if (t == null) { 41 | t = new Node(x); 42 | return; 43 | } 44 | int dir = x >= t->val; 45 | insert(t->ch[dir], x); 46 | if (t->ch[dir]->key < t->key) 47 | rot(t, dir); 48 | else 49 | t->update(); 50 | } 51 | 52 | void erase(Node *&t, int x) { 53 | if (t == null) 54 | return; 55 | if (t->val == x) { 56 | int dir = t->ch[1]->key < t->ch[0]->key; 57 | if (t->ch[dir] == null) { 58 | delete t; 59 | t = null; 60 | return; 61 | } 62 | rot(t, dir); 63 | erase(t->ch[! dir], x); 64 | t->update(); 65 | return; 66 | } 67 | bool dir = x > t->val; 68 | erase(t->ch[dir], x); 69 | t->update(); 70 | } 71 | 72 | void insert(int x) { 73 | insert(root, x); 74 | } 75 | 76 | void erase(int x) { 77 | erase(root, x); 78 | } 79 | }; 80 | \end{lstlisting} 81 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL/z.tex: -------------------------------------------------------------------------------- 1 | \begin{lstlisting} 2 | void z(char *s, int *next, int N) 3 | { 4 | int j = 0, k = 1; 5 | while (j + 1 < N && s[j] == s[j + 1]) ++ j; 6 | next[0] = N - 1; next[1] = j; 7 | for(int i = 2; i < N; ++ i) { 8 | int far = k + next[k] - 1, L = next[i - k]; 9 | if (L < far - i + 1) next[i] = L; 10 | else { 11 | j = max(0, far - i + 1); 12 | while (i + j < N && s[j] == s[i + j]) ++ j; 13 | next[i] = j; k = i; 14 | } 15 | } 16 | } 17 | \end{lstlisting} 18 | -------------------------------------------------------------------------------- /SCL-collection/template/SCL_gy.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/SCL_gy.zip -------------------------------------------------------------------------------- /SCL-collection/template/Seraphim模板.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/Seraphim模板.pdf -------------------------------------------------------------------------------- /SCL-collection/template/scl.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/scl.docx -------------------------------------------------------------------------------- /SCL-collection/template/shy.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/SCL-collection/template/shy.zip -------------------------------------------------------------------------------- /SCL-collection/template/shy/aczidongji.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int a[100001][27],fail[100001],last[100001],c[100001],l,father[100001],type[100001]; 9 | char can[1001]; 10 | 11 | inline void maketrie(){ 12 | memset(a,0,sizeof(a)); 13 | memset(type,0,sizeof(type)); 14 | memset(last,0,sizeof(last)); 15 | int n=strlen(can),now=0; 16 | l=0; 17 | for (int i=0;i 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int a[100001][27],fail[100001],last[100001],c[100001],l,father[100001],type[100001]; 10 | char can[1001]; 11 | 12 | inline void maketrie(){ 13 | memset(a,0,sizeof(a)); 14 | memset(type,0,sizeof(type)); 15 | memset(last,0,sizeof(last)); 16 | int n=strlen(can),now=0; 17 | l=0; 18 | for (int i=0;i= n) { 25 | int count = 0; 26 | for (int x = i, y = n; y;) { 27 | int t = from[x][y]; 28 | count += t == 1; 29 | x += DELTA[t][0]; 30 | y += DELTA[t][1]; 31 | } 32 | ret = std::max(ret, count); 33 | int x = i - n + 1, y = 0; 34 | from[x][0] = 0; 35 | while (y <= n && from[x][y] == 0) y++; 36 | for (; x <= i; ++ x) { 37 | from[x][y] = 0; 38 | if (x == i) break; 39 | for (; y <= n; ++ y) { 40 | if (from[x + 1][y] == 2) break; 41 | if (y + 1 <= n && from[x + 1][y + 1] == 1) { 42 | y ++; break; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | return ret; 49 | } 50 | -------------------------------------------------------------------------------- /improve/DominatorTree.cpp: -------------------------------------------------------------------------------- 1 | vector prec[N], succ[N]; 2 | vector ord; 3 | int stamp, vis[N]; 4 | int num[N]; 5 | int fa[N]; 6 | void dfs(int u) { 7 | vis[u] = stamp; 8 | num[u] = ord.size(); 9 | ord.push_back(u); 10 | for (int i = 0; i < (int)succ[u].size(); ++i) { 11 | int v = succ[u][i]; 12 | if (vis[v] != stamp) { 13 | fa[v] = u; 14 | dfs(v); 15 | } 16 | } 17 | } 18 | int fs[N], mins[N], dom[N], sem[N]; 19 | int find(int u) { 20 | if (u != fs[u]) { 21 | int v = fs[u]; 22 | fs[u] = find(fs[u]); 23 | if (mins[v] != -1 && num[sem[mins[v]]] < num[sem[mins[u]]]) { 24 | mins[u] = mins[v]; 25 | } 26 | } 27 | return fs[u]; 28 | } 29 | void merge(int u, int v) { fs[u] = v; } 30 | vector buf[N]; 31 | int buf2[N]; 32 | void mark(int source) { 33 | ord.clear(); 34 | ++stamp; 35 | dfs(source); 36 | for (int i = 0; i < (int)ord.size(); ++i) { 37 | int u = ord[i]; 38 | fs[u] = u, mins[u] = -1, buf2[u] = -1; 39 | } 40 | for (int i = (int)ord.size() - 1; i > 0; --i) { 41 | int u = ord[i], p = fa[u]; 42 | sem[u] = p; 43 | for (int j = 0; j < (int)prec[u].size(); ++j) { 44 | int v = prec[u][j]; 45 | if (use[v] != stamp) continue; 46 | if (num[v] > num[u]) { 47 | find(v); v = sem[mins[v]]; 48 | } 49 | if (num[v] < num[sem[u]]) { 50 | sem[u] = v; 51 | } 52 | } 53 | buf[sem[u]].push_back(u); 54 | mins[u] = u; 55 | merge(u, p); 56 | while (buf[p].size()) { 57 | int v = buf[p].back(); 58 | buf[p].pop_back(); 59 | find(v); 60 | if (sem[v] == sem[mins[v]]) { 61 | dom[v] = sem[v]; 62 | } else { 63 | buf2[v] = mins[v]; 64 | } 65 | } 66 | } 67 | dom[ord[0]] = ord[0]; 68 | for (int i = 0; i < (int)ord.size(); ++i) { 69 | int u = ord[i]; 70 | if (~buf2[u]) { 71 | dom[u] = dom[buf2[u]]; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /improve/FFT.cpp: -------------------------------------------------------------------------------- 1 | // double 精度对$10^9+7$ 取模最多可以做到$2^{20}$ 2 | const int MOD = 1000003; 3 | const double PI = acos(-1); 4 | typedef complex Complex; 5 | const int N = 65536, L = 15, MASK = (1 << L) - 1; 6 | Complex w[N]; 7 | void FFTInit() { 8 | for (int i = 0; i < N; ++i) { 9 | w[i] = Complex(cos(2 * i * PI / N), sin(2 * i * PI / N)); 10 | } 11 | } 12 | void FFT(Complex p[], int n) { 13 | for (int i = 1, j = 0; i < n - 1; ++i) { 14 | for (int s = n; j ^= s >>= 1, ~j & s;); 15 | if (i < j) { 16 | swap(p[i], p[j]); 17 | } 18 | } 19 | for (int d = 0; (1 << d) < n; ++d) { 20 | int m = 1 << d, m2 = m * 2, rm = n >> (d + 1); 21 | for (int i = 0; i < n; i += m2) { 22 | for (int j = 0; j < m; ++j) { 23 | Complex &p1 = p[i + j + m], &p2 = p[i + j]; 24 | Complex t = w[rm * j] * p1; 25 | p1 = p2 - t; 26 | p2 = p2 + t; 27 | } 28 | } 29 | } 30 | } 31 | Complex A[N], B[N], C[N], D[N]; 32 | void mul(int a[N], int b[N]) { 33 | for (int i = 0; i < N; ++i) { 34 | A[i] = Complex(a[i] >> L, a[i] & MASK); 35 | B[i] = Complex(b[i] >> L, b[i] & MASK); 36 | } 37 | FFT(A, N), FFT(B, N); 38 | for (int i = 0; i < N; ++i) { 39 | int j = (N - i) % N; 40 | Complex da = (A[i] - conj(A[j])) * Complex(0, -0.5), 41 | db = (A[i] + conj(A[j])) * Complex(0.5, 0), 42 | dc = (B[i] - conj(B[j])) * Complex(0, -0.5), 43 | dd = (B[i] + conj(B[j])) * Complex(0.5, 0); 44 | C[j] = da * dd + da * dc * Complex(0, 1); 45 | D[j] = db * dd + db * dc * Complex(0, 1); 46 | } 47 | FFT(C, N), FFT(D, N); 48 | for (int i = 0; i < N; ++i) { 49 | long long da = (long long)(C[i].imag() / N + 0.5) % MOD, 50 | db = (long long)(C[i].real() / N + 0.5) % MOD, 51 | dc = (long long)(D[i].imag() / N + 0.5) % MOD, 52 | dd = (long long)(D[i].real() / N + 0.5) % MOD; 53 | a[i] = ((dd << (L * 2)) + ((db + dc) << L) + da) % MOD; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /improve/FWT.cpp: -------------------------------------------------------------------------------- 1 | void FWT(int a[N], int N) { 2 | for (int d = 1; d < N; d <<= 1) { 3 | int d2 = d << 1; 4 | for (int i = 0; i < N; i += d2) { 5 | int *x = a + i, *y = a + i + d; 6 | for (int j = 0; j < d; ++j, ++x, ++y) { 7 | if ((*x += *y) >= MOD) { 8 | *x -= MOD; 9 | } 10 | if ((*y = *x - (*y << 1)) < 0) { 11 | if ((*y += MOD) < 0) { 12 | *y += MOD; 13 | } 14 | } 15 | } 16 | } 17 | } 18 | } 19 | 20 | void xorPow(int a[N], int n, int b[N]) { 21 | memset(b, 0, sizeof(int) * N); 22 | b[0] = 1; 23 | FWT(a, N); 24 | FWT(b, N); 25 | while(n) { 26 | if (n & 1) { 27 | dot(b, a, N); 28 | } 29 | dot(a, a, N); 30 | n >>= 1; 31 | } 32 | FWT(b, N); 33 | norm(b, N); 34 | } 35 | -------------------------------------------------------------------------------- /improve/Hungarian.cpp: -------------------------------------------------------------------------------- 1 | // 最小匹配, 自带初始化 n <= m 方案存在 p[] 中 2 | const int N = 105; 3 | const int INF = 1000000000; // 严格大于最大边权 4 | int n, m, a[N][N]; 5 | int u[N], v[N], p[N], fa[N], minv[N]; 6 | bool used[N]; 7 | int km() { 8 | memset(u, 0, sizeof(int) * n); 9 | for (int i = 0; i <= m; ++i) v[i] = 0, p[i] = n; 10 | for (int i = 0; i < n; ++i) { 11 | p[m] = i; 12 | int j0 = m; 13 | for (int j = 0; j <= m; ++j) minv[j] = INF, used[j] = false; 14 | do { 15 | used[j0] = true; 16 | int i0 = p[j0], delta = INF, j1; 17 | for (int j = 0; j < m; ++j) { 18 | if (!used[j]) { 19 | int cur = a[i0][j] - u[i0] - v[j]; 20 | if (cur < minv[j]) minv[j] = cur, fa[j] = j0; 21 | if (minv[j] < delta) delta = minv[j], j1 = j; 22 | } 23 | } 24 | for (int j = 0; j <= m; ++j) { 25 | if (used[j]) { 26 | u[p[j]] += delta, v[j] -= delta; 27 | } else { 28 | minv[j] -= delta; 29 | } 30 | } 31 | j0 = j1; 32 | } while (p[j0] != n); 33 | do { 34 | int j1 = fa[j0]; 35 | p[j0] = p[j1]; 36 | j0 = j1; 37 | } while (j0 != m); 38 | } 39 | return -v[m]; 40 | } 41 | -------------------------------------------------------------------------------- /improve/LCT.cpp: -------------------------------------------------------------------------------- 1 | // 注意初始化 null 节点,单点的 is_root 初始为 true 2 | struct Node{ 3 | Node *ch[2], *p; 4 | int is_root, rev; 5 | bool dir(); 6 | void set(Node*, bool); 7 | void update(); 8 | void relax(); 9 | void app_rev(); 10 | } *null; 11 | void rot(Node *t){ 12 | Node *p=t->p; bool d=t->dir(); 13 | p->relax(); t->relax(); p->set(t->ch[!d],d); 14 | if(p->is_root) t->p=p->p,swap(p->is_root,t->is_root); 15 | else p->p->set(t,p->dir()); 16 | t->set(p,!d); p->update(); 17 | } 18 | void splay(Node *t){ 19 | for(t->relax();!t->is_root;) 20 | if(t->p->is_root) rot(t); 21 | else t->dir()==t->p->dir() ?(rot(t->p),rot(t)) :(rot(t),rot(t)); 22 | t->update(); 23 | } 24 | void access(Node *t){ 25 | for(Node *s=null; t!=null; s=t,t=t->p){ 26 | splay(t); 27 | if (t->p == null) { /*TODO*/ } 28 | t->ch[1]->is_root=true; s->is_root=false; 29 | t->ch[1]=s; t->update(); 30 | } 31 | } 32 | bool Node::dir(){ return this==p->ch[1]; } 33 | void Node::set(Node *t,bool _d){ ch[_d]=t; t->p=this; } 34 | void Node::update(){ } 35 | void Node::app_rev(){ if (this == null) return; rev ^= true; swap(ch[0], ch[1]); } 36 | void Node::relax() { if(this==null) return; if (rev) { ch[0]->app_rev(); ch[1]->app_rev(); rev = false; } } 37 | void make_root(Node *u) { access(u); splay(u); u->app_rev(); } 38 | -------------------------------------------------------------------------------- /improve/LiuZhu.cpp: -------------------------------------------------------------------------------- 1 | const int MAXN,INF;// INF >= sum( W_ij ) 2 | int from[MAXN + 10][MAXN * 2 + 10],n,m,edge[MAXN + 10][MAXN * 2 + 10]; 3 | int sel[MAXN * 2 + 10],fa[MAXN * 2 + 10],vis[MAXN * 2 + 10]; 4 | int getfa(int x){if(x == fa[x]) return x; return fa[x] = getfa(fa[x]);} 5 | void liuzhu(){ // 1-base: root is 1, answer = (sel[i], i) for i in [2..n] 6 | fa[1] = 1; 7 | for(int i = 2; i <= n; ++i){ 8 | sel[i] = 1; fa[i] = i; 9 | for(int j = 1; j <= n; ++j) if(fa[j] != i) 10 | if(from[j][i] = i, edge[sel[i]][i] > edge[j][i]) sel[i] = j; 11 | } 12 | int limit = n; 13 | while(1){ 14 | int prelimit = limit; memset(vis, 0, sizeof(vis)); vis[1] = 1; 15 | for(int i = 2; i <= prelimit; ++i) if(fa[i] == i && !vis[i]){ 16 | int j = i; while(!vis[j]) vis[j] = i, j = getfa(sel[j]); 17 | if(j == 1 || vis[j] != i) continue; vector C; int k = j; 18 | do C.push_back(k), k = getfa(sel[k]); while(k != j); 19 | ++limit; 20 | for(int i = 1; i <= n; ++i){ 21 | edge[i][limit] = INF, from[i][limit] = limit; 22 | } 23 | fa[limit] = vis[limit] = limit; 24 | for(int i = 0; i < int(C.size()); ++i){ 25 | int x = C[i], fa[x] = limit; 26 | for(int j = 1; j <= n; ++j) 27 | if(edge[j][x] != INF && edge[j][limit] > edge[j][x] - edge[sel[x]][x]){ 28 | edge[j][limit] = edge[j][x] - edge[sel[x]][x]; 29 | from[j][limit] = x; 30 | } 31 | } 32 | for(int j=1;j<=n;++j) if(getfa(j)==limit) edge[j][limit] = INF; 33 | sel[limit] = 1; 34 | for(int j = 1; j <= n; ++j) 35 | if(edge[sel[limit]][limit] > edge[j][limit]) sel[limit] = j; 36 | } 37 | if(prelimit == limit) break; 38 | } 39 | for(int i = limit; i > 1; --i) sel[from[sel[i]][i]] = sel[i]; 40 | } 41 | -------------------------------------------------------------------------------- /improve/MincostFlow.cpp: -------------------------------------------------------------------------------- 1 | // Q is a priority_queue, greater > 2 | // for an edge(s, t): u is the capacity, v is the cost, nxt is the next edge, 3 | // op is the opposite edge 4 | // this code can not deal with negative cycles 5 | typedef pair PII; 6 | struct edge{ int t,u,v; edge *nxt,*op; }E[MAXE],*V[MAXV]; 7 | int D[MAXN], dist[MAXN], maxflow, mincost; bool in[MAXN]; 8 | bool modlabel(){ 9 | while(!Q.empty()) Q.pop(); 10 | for(int i=S;i<=T;++i) if(in[i]) D[i]=0,Q.push(PII(0,i)); else D[i]=inf; 11 | while(!Q.empty()){ 12 | int x=Q.top().first,y=Q.top().second; Q.pop(); 13 | if(y==T) break; if(D[y]nxt) if(ii->u) 15 | if(x+(ii->v+dist[ii->t]-dist[y])t]){ 16 | D[ii->t]=x+(ii->v+dist[ii->t]-dist[y]); 17 | Q.push(PII(D[ii->t],ii->t)); 18 | } 19 | } 20 | if(D[T]==inf) return false; 21 | for(int i=S;i<=T;++i) if(D[i]>D[T]) dist[i]+=D[T]-D[i]; 22 | return true; 23 | } 24 | int aug(int p,int limit){ 25 | if(p==T) return maxflow+=limit,mincost+=limit*dist[S],limit; 26 | in[p]=1; int kk,ll=limit; 27 | for(edge *ii=V[p];ii;ii=ii->nxt) if(ii->u){ 28 | if(!in[ii->t]&&dist[ii->t]+ii->v==dist[p]){ 29 | kk=aug(ii->t,min(ii->u,ll)); ll-=kk,ii->u-=kk,ii->op->u+=kk; 30 | if(!ll) return in[p]=0,limit; 31 | } 32 | } 33 | return limit-ll; 34 | } 35 | PII mincostFlow(){ 36 | for(int i=S;i<=T;++i) dist[i]=i==T?inf:0; 37 | while(!Q.empty()) Q.pop(); Q.push(PII(0,T)); 38 | while(!Q.empty()){ 39 | int x=Q.top().first,y=Q.top().second; Q.pop(); if(dist[y]nxt) if(ii->op->u&&ii->v+xt] 41 | dist[ii->t]=ii->v+x,Q.push(PII(dist[ii->t],ii->t)); 42 | } 43 | maxflow=mincost=0; 44 | do{ 45 | do{ 46 | memset(in,0,sizeof(in)); 47 | }while(aug(S,maxflow)); 48 | }while(modlabel()); 49 | return PII(maxflow,mincost); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /improve/NTT.cpp: -------------------------------------------------------------------------------- 1 | //R 是 2^n*q+1 形质数 p 的原根 2 | void NFT(int P[], int n, int oper) { 3 | for (int i = 1, j = 0; i < n - 1; ++i) { 4 | for (int s = n; j ^= s >>= 1, ~j & s;); 5 | if (i < j) { 6 | swap(P[i], P[j]); 7 | } 8 | } 9 | for (int d = 0; (1 << d) < n; ++d) { 10 | int m = 1 << d, m2 = m * 2; 11 | int unit_p0 = powmod(R, (MOD - 1) / m2); 12 | if (oper < 0) { 13 | unit_p0 = inverse(unit_p0); 14 | } 15 | for (int i = 0; i < n; i += m2) { 16 | int unit = 1; 17 | for (int j = 0; j < m; ++j) { 18 | int &P1 = P[i + j + m], 19 | &P2 = P[i + j]; 20 | int t = (long long)unit * P1 % MOD; 21 | P1 = (P2 - t + MOD) % MOD; 22 | P2 = (P2 + t) % MOD; 23 | unit = (long long)unit * unit_p0 % MOD; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /improve/Triangle.cpp: -------------------------------------------------------------------------------- 1 | Point inCenter(const Point &A, const Point &B, const Point &C) { // 内心 2 | double a = (B - C).len(), b = (C - A).len(), c = (A - B).len(), 3 | s = fabs(det(B - A, C - A)), 4 | r = s / p; 5 | return (A * a + B * b + C * c) / (a + b + c); 6 | } 7 | Point circumCenter(const Point &a, const Point &b, const Point &c) { // 外心 8 | Point bb = b - a, cc = c - a; 9 | double db = bb.len2(), dc = cc.len2(), d = 2 * det(bb, cc); 10 | return a - Point(bb.y * dc - cc.y * db, cc.x * db - bb.x * dc) / d; 11 | } 12 | Point othroCenter(const Point &a, const Point &b, const Point &c) { // 垂心 13 | Point ba = b - a, ca = c - a, bc = b - c; 14 | double Y = ba.y * ca.y * bc.y, 15 | A = ca.x * ba.y - ba.x * ca.y, 16 | x0 = (Y + ca.x * ba.y * b.x - ba.x * ca.y * c.x) / A, 17 | y0 = -ba.x * (x0 - c.x) / ba.y + ca.y; 18 | return Point(x0, y0); 19 | } 20 | -------------------------------------------------------------------------------- /improve/日期公式.cpp: -------------------------------------------------------------------------------- 1 | int zeller(int y,int m,int d) { 2 | if (m<=2) y--,m+=12; int c=y/100; y%=100; 3 | int w=((c>>2)-(c<<1)+y+(y>>2)+(13*(m+1)/5)+d-1)%7; 4 | if (w<0) w+=7; return(w); 5 | } 6 | int getId(int y, int m, int d) { 7 | if (m < 3) {y --; m += 12}; 8 | return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m + 2) / 5 + d; 9 | } 10 | -------------------------------------------------------------------------------- /main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/main.pdf -------------------------------------------------------------------------------- /merge/HalfPlaneIntersection.cpp: -------------------------------------------------------------------------------- 1 | struct Point { 2 | int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0);} 3 | }; 4 | struct Line { 5 | bool include(const Point &p) const { return sign(det(b - a, p - a)) > 0; } 6 | Line push() const{ // 将半平面向外推 eps 7 | const double eps = 1e-6; 8 | Point delta = (b - a).turn90().norm() * eps; 9 | return Line(a - delta, b - delta); 10 | } 11 | }; 12 | bool sameDir(const Line &l0, const Line &l1) { return parallel(l0, l1) && sign(dot(l0.b - l0.a, l1.b - l1.a)) == 1; } 13 | bool operator < (const Point &a, const Point &b) { 14 | if (a.quad() != b.quad()) { 15 | return a.quad() < b.quad(); 16 | } else { 17 | return sign(det(a, b)) > 0; 18 | } 19 | } 20 | bool operator < (const Line &l0, const Line &l1) { 21 | if (sameDir(l0, l1)) { 22 | return l1.include(l0.a); 23 | } else { 24 | return (l0.b - l0.a) < (l1.b - l1.a); 25 | } 26 | } 27 | bool check(const Line &u, const Line &v, const Line &w) { return w.include(intersect(u, v)); } 28 | vector intersection(vector &l) { 29 | sort(l.begin(), l.end()); 30 | deque q; 31 | for (int i = 0; i < (int)l.size(); ++i) { 32 | if (i && sameDir(l[i], l[i - 1])) { 33 | continue; 34 | } 35 | while (q.size() > 1 && !check(q[q.size() - 2], q[q.size() - 1], l[i])) q.pop_back(); 36 | while (q.size() > 1 && !check(q[1], q[0], l[i])) q.pop_front(); 37 | q.push_back(l[i]); 38 | } 39 | while (q.size() > 2 && !check(q[q.size() - 2], q[q.size() - 1], q[0])) q.pop_back(); 40 | while (q.size() > 2 && !check(q[1], q[0], q[q.size() - 1])) q.pop_front(); 41 | vector ret; 42 | for (int i = 0; i < (int)q.size(); ++i) ret.push_back(intersect(q[i], q[(i + 1) % q.size()])); 43 | return ret; 44 | } 45 | -------------------------------------------------------------------------------- /merge/Manacher.cpp: -------------------------------------------------------------------------------- 1 | void Manacher(char text[], int n, int palindrome[]) { 2 | palindrome[0] = 1; 3 | for (int i = 1, j = 0, i < (n << 1) - 1; ++ i) { 4 | int p = i >> 1; 5 | int q = i - p; 6 | int r = (j + 1 >> 1) + palindrome[j] - 1; 7 | palindrome[i] = r < q ? 0 : min(r - q + 1, palindrome[(j << 1) - i]); 8 | while (0 <= p - palindrome[i] && q + palindrome[i] < n && text[p - palindrome[i]] == text[q + palindrome[i]]) { 9 | palindrome[i] ++; 10 | } 11 | if (q + palindrome[i] - 1 > r) { 12 | j = i; 13 | } 14 | } 15 | } 16 | 17 | void ExtendedKMP(char *s, int next[]) { 18 | int l = strlen(s), i = 0, j = 0, k = 1; 19 | while (1 + j < l && s[j] == s[1 + j]) { 20 | ++j; 21 | } 22 | next[1] = j; 23 | for (int i = 2; i < l; ++i) { 24 | int len = k + next[k], ll = next[i - k]; 25 | if (ll < len - i) { 26 | next[i] = ll; 27 | } else { 28 | j = max(0, len - i); 29 | while (i + j < l && s[j] == s[i + j]) { 30 | ++j; 31 | } 32 | next[i] = j; 33 | k = i; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /merge/areaCT.cpp: -------------------------------------------------------------------------------- 1 | double areaCT(Point pa, Point pb, double r) { 2 | if (pa.len() < pb.len()) swap(pa, pb); 3 | if (sign(pb.len()) == 0) return 0; 4 | double a = pb.len(), b = pa.len(), c = (pb - pa).len(); 5 | double sinB = fabs(det(pb, pb - pa) / a / c), 6 | cosB = dot(pb, pb - pa) / a / c, 7 | sinC = fabs(det(pa, pb) / a/ b), 8 | cosC = dot(pa, pb) / a / b; 9 | double B = atan2(sinB, cosB), C = atan2(sinC, cosC); 10 | if (a > r) { 11 | S = C / 2 * r * r; 12 | h = a * b * sinC / c; 13 | if (h < r && B < PI / 2) { 14 | S -= (acos(h / r) * r * r - h * sqrt(r * r - h * h)); 15 | } 16 | } else if (b > r) { 17 | double theta = PI - B - asin(sinB / r * a); 18 | S = a * r * sin(theta) / 2 + (C - theta) / 2 * r * r; 19 | } else { 20 | S = sinC * a * b / 2; 21 | } 22 | return S; 23 | } 24 | -------------------------------------------------------------------------------- /src/DC3.cpp: -------------------------------------------------------------------------------- 1 | // 待排序的字符串放在 r 数组中, 从 r[0] 到 r[n-1], 长度为 n, 且最大值小于 m 2 | // 约定除 r[n-1] 外所有的 r[i] 都大于 0, r[n-1]=0 3 | // 函数结束后, 结果放在 sa 数组中, 从 sa[0] 到 sa[n-1] 4 | #define maxn 10000 5 | #define F(x) ((x)/3+((x)%3==1?0:tb)) 6 | #define G(x) ((x)=0;i--) b[--wss[wv[i]]]=a[i]; 19 | } 20 | void dc3(int *r,int *sa,int n,int m){ 21 | int i,j,*rn=r+n,*san=sa+n,ta=0,tb=(n+1)/3,tbc=0,p; 22 | r[n]=r[n+1]=0; 23 | for(i=0;i &V,int rownum){ 6 | std::vector N; 7 | for(int i=0;irow=rownum; 9 | now->col=now->up=col[V[i]], now->down=col[V[i]]->down; 10 | now->up->down=now, now->down->up=now; 11 | now->col->cnt++; N.push_back(now); 12 | } 13 | for(int i=0;iright=N[(i+1)%V.size()], N[i]->left=N[(i-1+V.size())%V.size()]; 15 | } 16 | void Remove(node *x){ 17 | x->left->right=x->right, x->right->left=x->left; 18 | for(node *i=x->down;i!=x;i=i->down) 19 | for(node *j=i->right;j!=i;j=j->right) 20 | j->up->down=j->down, j->down->up=j->up, --(j->col->cnt); 21 | } 22 | void Resume(node *x){ 23 | for(node *i=x->up;i!=x;i=i->up) 24 | for(node *j=i->left;j!=i;j=j->left) 25 | j->up->down=j->down->up=j, ++(j->col->cnt); 26 | x->left->right=x, x->right->left=x; 27 | } 28 | bool search(int tot){ 29 | if(head->right==head) return true; 30 | node *choose=NULL; 31 | for(node *i=head->right;i!=head;i=i->right){ 32 | if(choose==NULL||choose->cnt>i->cnt) choose=i; 33 | if(choose->cnt<2) break; 34 | } 35 | Remove(choose); 36 | for(node *i=choose->down;i!=choose;i=i->down){ 37 | for(node *j=i->right;j!=i;j=j->right) Remove(j->col); 38 | ans[tot]=i; 39 | if(search(tot+1)) return true; 40 | ans[tot]=NULL; 41 | for(node *j=i->left;j!=i;j=j->left) Resume(j->col); 42 | } 43 | Resume(choose); 44 | return false; 45 | } 46 | void prepare(int totC){ 47 | head=Node+totC; 48 | for(int i=0;iright=Node+(i+1)%(totC+1); 52 | (Node+i)->left=Node+(i+totC)%(totC+1); 53 | (Node+i)->up=(Node+i)->down=Node+i; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/DancingLinks.tex: -------------------------------------------------------------------------------- 1 | 2 | 如果矩阵中所有的列均被删除 , 找到一组合法解 , 退出 \\ 3 | 任意选择一个未被删除的列 c , \\ 4 | 枚举一个未被删除的行 r, 且 Matrix[r][c]=1, 将 (r, c) 加入 Ans \\ 5 | 枚举所有的列 j, Matrix[r][j]=1, 将第 j 列删除\\ 6 | 枚举所有的行 i, Matrix[i][j]=1, 将第 i 行删除 7 | % AlgorithmX(Dep + 1) 8 | 9 | %Procedure AlgorithmX(Dep) 10 | % 如果h->right = h(即所有的列均被删除), 找到一组解, 退出. 11 | % 利用h和right指针找到一个c, 满足size[c]最小. 12 | % 如果size[c] = 0(当前列无法被覆盖), 无解, 退出. 13 | %Cover(c) 14 | % for (i = c->down; i != c; i ← i->down) 15 | % for (j = i->right; j != i; j ← j->right) Cover(j->col) 16 | % 将i结点加入Ans, AlgorithmX(Dep + 1) 17 | % for (j = i->left; j != i; j ← j->left) Recover(j->col) 18 | % Recover(c) 19 | %Soduku问题可以转化一个Exact Cover Problem:16 * 16 * 16行, (i, j, k)表示(i, j)这个格子填上字母k.16 * 16 * 4列分别表示第i行中的字母k, 第i列中的字母k, 第i个子矩阵中的字母k, 以及(i, j)这个格子.对于每个集合(i, j, k), 它包含了4个元素:Line(i, k), Col(j, k), Sub(P[i][j], k), Grid(i, j), 其中P[i][j]表示(i, j)这个格子所属的子矩阵.本题转化为一个4096行, 1024列, 且1的个数为16384个的矩阵.下面介绍解决一般的Exact Cover Problem的AlgorithmX. 20 | %N皇后问题:关键是构建Exact Cover问题的矩阵:N * N行对应了N * N个格子, 6N-2列对应了N行, N列, 2N-1条主对角线, 2N-1条副对角线.第i行共4个1, 分别对应(i, j)这个格子所处的行, 列, 主对角线和副对角线.直接对这个矩阵作AlgorithmX是错误的, 虽然每行, 每列都恰好被覆盖一次, 但是对角线是最多覆盖一次, 它可以不被覆盖, 这与Exact Cover问题的定义是不同的. 21 | %有两种处理的方法: 22 | %1) 新增4N-2行, 每行只有一个1, 分别对应了2N-1条主对角线和2N-1条副对角线, 这样就可以保证某个对角线不被覆盖的时候, 可以使用新增行来覆盖. 23 | %2) 每次选择一个size[]值最小的列c进行覆盖, 而这一步, 我们忽略掉所有的对角线列, 只考虑c为行和列的情况. 24 | %事实证明, 第2)种方法的效果好很多, 因此这个问题可以使用AlgorithmX轻松得到解决. 25 | 26 | 27 | \inputminted{cpp}{src/DancingLinks.cpp} 28 | -------------------------------------------------------------------------------- /src/DancingLinks.tex.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@setckpt{src/DancingLinks.tex}{ 3 | \setcounter{page}{20} 4 | \setcounter{equation}{0} 5 | \setcounter{enumi}{0} 6 | \setcounter{enumii}{0} 7 | \setcounter{enumiii}{0} 8 | \setcounter{enumiv}{0} 9 | \setcounter{footnote}{0} 10 | \setcounter{mpfootnote}{0} 11 | \setcounter{part}{0} 12 | \setcounter{section}{0} 13 | \setcounter{subsection}{0} 14 | \setcounter{subsubsection}{0} 15 | \setcounter{paragraph}{0} 16 | \setcounter{subparagraph}{0} 17 | \setcounter{figure}{0} 18 | \setcounter{table}{0} 19 | \setcounter{lstnumber}{1} 20 | \setcounter{FancyVerbLine}{17} 21 | \setcounter{float@type}{16} 22 | \setcounter{linenumber}{1} 23 | \setcounter{LN@truepage}{20} 24 | \setcounter{FancyVerbLineBreakLast}{2} 25 | \setcounter{minted@FancyVerbLineTemp}{0} 26 | \setcounter{listing}{0} 27 | \setcounter{lstlisting}{0} 28 | } 29 | -------------------------------------------------------------------------------- /src/Hopcroft.cpp: -------------------------------------------------------------------------------- 1 | // 左侧 N 个点, 右侧 K 个点 , 1-based, 初始化将 matx[],maty[] 都置为 0 2 | int N, K; 3 | int que[N], dx[N], dy[N], matx[N], maty[N]; 4 | int BFS() 5 | { 6 | int flag = 0, qt = 0, qh = 0; 7 | for(int i = 1; i <= K; ++ i) dy[i] = 0; 8 | for(int i = 1; i <= N; ++ i) { 9 | dx[i] = 0; 10 | if (! matx[i]) que[qt ++] = i; 11 | } 12 | while (qh < qt) { 13 | int u = que[qh ++]; 14 | for(Edge *e = E[u]; e; e = e->n) 15 | if (! dy[e->t]) { 16 | dy[e->t] = dx[u] + 1; 17 | if (! maty[e->t]) flag = true; 18 | else { 19 | dx[maty[e->t]] = dx[u] + 2; 20 | que[qt ++] = maty[e->t]; 21 | } 22 | } 23 | } 24 | return flag; 25 | } 26 | int DFS(int u) 27 | { 28 | for(Edge *e = E[u]; e; e = e->n) 29 | if (dy[e->t] == dx[u] + 1) { 30 | dy[e->t] = 0; 31 | if (! maty[e->t] || DFS(maty[e->t])) { 32 | matx[u] = e->t; maty[e->t] = u; 33 | return true; 34 | } 35 | } 36 | return false; 37 | } 38 | void Hopcroft() 39 | { 40 | while (BFS()) for(int i = 1; i <= N; ++ i) if (! matx[i]) DFS(i); 41 | } 42 | -------------------------------------------------------------------------------- /src/KDTree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/KDTree -------------------------------------------------------------------------------- /src/KM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/KM -------------------------------------------------------------------------------- /src/KM.cpp: -------------------------------------------------------------------------------- 1 | const int maxn=200;const int oo=0x7fffffff; 2 | int w[maxn][maxn],x[maxn],y[maxn],px[maxn],py[maxn],sy[maxn],slack[maxn]; 3 | int par[maxn];int n;int pa[200][2],pb[200][2],n0,m0,na,nb;char s[200][200]; 4 | void adjust(int v){ sy[v]=py[v]; if (px[sy[v]]!=-2) adjust(px[sy[v]]);} 5 | bool find(int v){for (int i=0;ix[v]+y[i]-w[v][i]) slack[i]=x[v]+y[i]-w[v][i], par[i]=v; 8 | if (x[v]+y[i]==w[v][i]){ 9 | py[i]=v; if (sy[i]==-1){adjust(i); return 1;} 10 | if (px[sy[i]]!=-1) continue; px[sy[i]]=i; 11 | if (find(sy[i])) return 1; 12 | }}return 0;} 13 | int km(){int i,j,m,flag; for (i=0;ip; bool d=t->dir(); 8 | p->relax(); t->relax(); p->set(t->ch[!d],d); 9 | if(p->isRoot) t->p=p->p,swap(p->isRoot,t->isRoot); 10 | else p->p->set(t,p->dir()); 11 | t->set(p,!d); p->update(); 12 | } 13 | void splay(Node *t){ 14 | for(t->relax();!t->isRoot;) 15 | if(t->p->isRoot) rot(t); 16 | else t->dir()==t->p->dir() ?(rot(t->p),rot(t)) :(rot(t),rot(t)); 17 | t->update(); 18 | } 19 | void access(Node *t){ 20 | for(Node *s=null; t!=null; s=t,t=t->p){ 21 | splay(t); 22 | t->ch[1]->isRoot=true; s->isRoot=false; 23 | t->ch[1]=s; t->update(); 24 | } 25 | } 26 | bool Node::dir(){ return this==p->ch[1]; } 27 | void Node::set(Node *t,bool _d){ ch[_d]=t; t->p=this; } 28 | void Node::update(){} 29 | void Node::relax(){ if(this==null) return; } -------------------------------------------------------------------------------- /src/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/Main.class -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.math.*; 4 | public class Main{ 5 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 6 | PrintWriter writer = new PrintWriter(System.out); 7 | StringTokenizer tokenizer = null; 8 | void solve() throws Exception { 9 | } 10 | void run()throws Exception{ 11 | try{ 12 | while (true) { 13 | solve(); 14 | } 15 | } 16 | catch(Exception e){ 17 | } 18 | finally{ 19 | reader.close(); 20 | writer.close(); 21 | } 22 | } 23 | String next()throws Exception{ 24 | for(;tokenizer == null || !tokenizer.hasMoreTokens();){ 25 | tokenizer = new StringTokenizer(reader.readLine()); 26 | } 27 | return tokenizer.nextToken(); 28 | } 29 | int nextInt()throws Exception{ 30 | return Integer.parseInt(next()); 31 | } 32 | double nextDouble()throws Exception{ 33 | return Double.parseDouble(next()); 34 | } 35 | BigInteger nextBigInteger()throws Exception{ 36 | return new BigInteger(next()); 37 | } 38 | public static void main(String args[])throws Exception{ 39 | (new Main()).run(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/NTT.cpp: -------------------------------------------------------------------------------- 1 | const int N = , P = 786433, G = 10; 2 | void dft(int *x, int on, int n) { 3 | int k, id, r, tmp, u, t; 4 | for(int i = 1, j = n >> 1; i < n - 1; ++ i) { 5 | if (i < j) swap(x[i], x[j]); 6 | for(k = n >> 1; j >= k; j -= k, k >>= 1); 7 | j += k; 8 | } 9 | for(int h = 2; h <= n; h <<= 1) { 10 | r = modPow(G, (P - 1) / h, P); 11 | if (on < 0) r = modPow(r, P - 2, P); 12 | for(int j = 0, p = h >> 1; j < n; j += h) { 13 | for(int k = j, w = 1; k < j + p; k ++) { 14 | u = x[k]; id = k + p; 15 | t = (long long)w * x[id] % P; 16 | x[k] = (u + t) % P; 17 | x[id] = (u - t + P) % P; 18 | w = (long long)w * r % P; 19 | }}}} 20 | int xa[N], xb[N]; 21 | void dft(int *a, int lenA, int *b, int lenB, int *ans, int &lenAns) { 22 | for(lenAns = 1; lenAns < lenA + lenB; lenAns <<= 1); 23 | for(int i = 0; i < lenAns; ++ i) xa[i] = xb[i] = 0; 24 | for(int i = 0; i < lenA; ++ i) xa[i] = a[i] % P; 25 | for(int i = 0; i < lenB; ++ i) xb[i] = b[i] % P; 26 | dft(xa, 1, lenAns); dft(xb, 1, lenAns); 27 | for(int i = 0; i < lenAns; ++ i) xa[i] = (long long)xa[i] * xb[i] % P; 28 | dft(xa, -1, lenAns); 29 | int tmp = modPow(lenAns, P - 2, P); 30 | for(int i = 0; i < lenAns; ++ i) ans[i] = (long long)xa[i]* tmp % P; 31 | } 32 | -------------------------------------------------------------------------------- /src/Pell方程.cpp: -------------------------------------------------------------------------------- 1 | ULL A,B,p[maxn],q[maxn],a[maxn],g[maxn],h[maxn]; 2 | int main() { 3 | for (int test=1, n;scanf("%d",&n) && n;++test) { 4 | printf("Case %d: ",test); 5 | if (fabs(sqrt(n)-floor(sqrt(n)+1e-7))<=1e-7) { 6 | int a=(int)(floor(sqrt(n)+1e-7)); printf("%d %d\n",a,1); 7 | } else { 8 | // 求 $x^2-ny^2=1$ 的最小正整数根, n 不是完全平方数 9 | p[1]=q[0]=h[1]=1;p[0]=q[1]=g[1]=0; 10 | a[2]=(int)(floor(sqrt(n)+1e-7)); 11 | for (int i=2;i;++i) { 12 | g[i]=-g[i-1]+a[i]*h[i-1]; h[i]=(n-sqr(g[i]))/h[i-1]; 13 | a[i+1]=(g[i]+a[2])/h[i]; p[i]=a[i]*p[i-1]+p[i-2]; 14 | q[i]=a[i]*q[i-1]+q[i-2]; 15 | if (sqr((ULL)(p[i]))-n*sqr((ULL)(q[i]))==1){ 16 | A=p[i];B=q[i];break; 17 | } 18 | } 19 | cout << A << ' ' << B < 2 | double romberg(const T&f,double a,double b,double eps=1e-8){ 3 | std::vectort; double h=b-a,last,curr; int k=1,i=1; 4 | t.push_back(h*(f(a)+f(b))/2); // 梯形 5 | do{ last=t.back(); curr=0; double x=a+h/2; 6 | for(int j=0;jeps); 12 | return t.back(); 13 | } 14 | -------------------------------------------------------------------------------- /src/Splay.cpp: -------------------------------------------------------------------------------- 1 | // 注意初始化内存池和 null 节点 2 | struct Node{ 3 | int rev,size; Node *ch[2],*p; 4 | void set(Node*,int); int dir(); void update(); void relax(); void appRev(); 5 | } nodePool[MAX_NODE],*curNode,*null; 6 | Node *newNode(){ 7 | Node *t=curNode++; t->rev=0, t->size=1; 8 | t->ch[0]=t->ch[1]=t->p=null; return t; 9 | } 10 | struct Splay{ 11 | Node *root; 12 | Splay(){ root=newNode(); root->set(newNode(),0); root->update(); } 13 | void rot(Node *t){ 14 | Node *p=t->p; int d=t->dir(); 15 | p->relax(); t->relax(); 16 | if(p==root) root=t; 17 | p->set(t->ch[!d],d); p->p->set(t,p->dir()); t->set(p,!d); 18 | p->update(); 19 | } 20 | void splay(Node *t,Node *f=null){ 21 | for(t->relax();t->p!=f;) 22 | if(t->p->p==f) rot(t); 23 | else t->dir()==t->p->dir()?(rot(t->p),rot(t)):(rot(t),rot(t)); 24 | t->update(); 25 | } 26 | }; 27 | void initNull(){ curNode=nodePool;null=curNode++;null->size=0; } 28 | void Node::set(Node *t,int _d){ ch[_d]=t; t->p=this; } 29 | int Node::dir(){ return this==p->ch[1]; } 30 | void Node::update(){ size=ch[0]->size+ch[1]->size+1;} 31 | void Node::relax(){ if(rev) ch[0]->appRev(), ch[1]->appRev(), rev=false; } 32 | void Node::appRev(){ if(this==null) return; rev^=true; swap(ch[0],ch[1]); } -------------------------------------------------------------------------------- /src/check/HDU2389Hopcroft.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define REP(i, n) for (int i = 0; i < (int)(n); i++) 6 | 7 | const int maxn = 3010; 8 | const int maxm = maxn * maxn; 9 | 10 | int from[maxn],wh[maxn],g[maxn]; 11 | int num[maxm],nxt[maxm],tot; 12 | int n,m,ans,h,t,q[maxn],dx[maxn],dy[maxn]; 13 | bool bfs(){ 14 | bool ret=false; 15 | h=0;t=0; 16 | for(int i=0;i= SQR(x[i] - x[n + j]) + SQR(y[i] - y[n + j])) 62 | insert(i, j); 63 | ans=0; hopcroft(); 64 | printf("Scenario #%d:\n%d\n\n",CNT+1, ans); 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/check/POJ2914无向图最小割.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | const int maxn = 505; 6 | const int inf = (int)1e9; 7 | int cost[maxn][maxn],seq[maxn],len[maxn],n,m,pop,ans; 8 | bool used[maxn]; 9 | void Init(){ 10 | int i,j,a,b,c; 11 | for(i=0;i 1){ 20 | for(i=1;i mm){ mm=len[seq[i]]; k=i; } 24 | for(i=1;i mm) 31 | mm=len[seq[j]], k=j; 32 | } 33 | sum=0; 34 | for(i=0;i> 1; i < n - 1; ++ i) { 5 | if (i < j) swap(x[i], x[j]); 6 | for(k = n >> 1; j >= k; j -= k, k >>= 1); 7 | j += k; 8 | } 9 | for (int h = 2; h <= n; h <<= 1) { 10 | r = on * 2.0 * PI / h; 11 | Complex wn(cos(r), sin(r)); 12 | for (int j = 0, p = h >> 1; j < n; j += h) { 13 | Complex w(1, 0); 14 | for (k = j; k < j + p; k++) { 15 | u = x[k]; id = k + p; 16 | t.real = w.real * x[id].real - w.imag * x[id].imag; 17 | t.imag = w.real * x[id].imag + w.imag * x[id].real; 18 | x[k].real = u.real + t.real; 19 | x[k].imag = u.imag + t.imag; 20 | x[id].real = u.real - t.real; 21 | x[id].imag = u.imag - t.imag; 22 | tmp = w.real; 23 | w.real = w.real * wn.real - w.imag * wn.imag; 24 | w.imag = tmp * wn.imag + w.imag * wn.real; 25 | }}}} 26 | Complex xa[N], xb[N]; 27 | void multiply(int *a, int lenA, int *b, int lenB, long long *ans, int &lenAns) { 28 | for(lenAns = 1; lenAns < lenA + lenB; lenAns <<= 1); 29 | for(int i = 0; i < lenAns; ++ i) 30 | xa[i].real = xa[i].imag = xb[i].real = xb[i].imag = 0; 31 | for(int i = 0; i < lenA; ++ i) xa[i].real = a[i]; 32 | for(int i = 0; i < lenB; ++ i) xb[i].real = b[i]; 33 | discreteFourierTransform(xa, 1, lenAns); 34 | discreteFourierTransform(xb, 1, lenAns); 35 | for(int i = 0; i < lenAns; ++ i) xa[i] = xa[i] * xb[i]; 36 | discreteFourierTransform(xa, -1, lenAns); 37 | for(int i = 0; i < lenAns; ++ i) ans[i]=(long long)(xa[i].real/lenAns+0.5); 38 | } 39 | -------------------------------------------------------------------------------- /src/list.in: -------------------------------------------------------------------------------- 1 | DancingLinks.cpp 2 | DC3.cpp 3 | Hopcroft.cpp 4 | KM.cpp 5 | nlogn半平面交.cpp 6 | NTT.cpp 7 | Pell方程.cpp 8 | Romberg.cpp 9 | 三维几何操作合并.cpp 10 | 三维凸包(n^2).cpp 11 | 三维凸包求重心.cpp 12 | 三维旋转操作.cpp 13 | 三角形的心.cpp 14 | 二次剩余.cpp 15 | 二维几何.cpp 16 | 动态最小生成树.cpp 17 | 动态树.cpp 18 | 后缀数组(nlogn).cpp 19 | 后缀自动机.cpp 20 | 启发式分解.cpp 21 | 回文串manacher.cpp 22 | 圆的面积模板(n^2logn).cpp 23 | 多边形与圆面积交.cpp 24 | 字符串最小表示.cpp 25 | 带花树.cpp 26 | 无向图最小割.cpp 27 | 最大团.cpp 28 | 最小覆盖球.cpp 29 | 最远点对.cpp 30 | 极大团计数.cpp 31 | 直线和凸包交点(返回最近和最远点).cpp 32 | 素数判定.cpp 33 | 线性规划.cpp 34 | 经纬度求球面最短距离.cpp 35 | 蔡勒公式.cpp 36 | 长方体表面两点最短距离.cpp 37 | -------------------------------------------------------------------------------- /src/table.in: -------------------------------------------------------------------------------- 1 | 多边形与圆面积交 2 2 | 二维几何 2 3 | nlogn半平面交 5 4 | 三维几何操作合并 6 5 | 三维旋转操作 7 6 | 三维凸包 9 7 | 直线和凸包交点(返回最近和最远点) 10 8 | 圆的面积模板(n^2logn) 11 9 | 三角形的心 13 10 | 最小覆盖球 14 11 | 经纬度求球面最短距离 15 12 | 长方体表面两点最短距离 16 13 | 最大团 16 14 | 极大团计数 17 15 | KM 18 16 | 无向图最小割 19 17 | 带花树 20 18 | 动态最小生成树 21 19 | Hopcroft 24 20 | 素数判定 25 21 | 启发式分解 25 22 | 二次剩余 27 23 | Pell方程 28 24 | 蔡勒公式 29 25 | Romberg 29 26 | 线性规划 29 27 | FFT && NTT 30 28 | 回文串manacher 31 29 | 后缀数组(nlogn) 32 30 | DC3 32 31 | 后缀自动机 33 32 | 字符串最小表示 33 33 | DancingLinks 34 34 | 弦图的完美消除序列 35 35 | 图同构Hash 35 36 | 魔方旋转群 35 37 | 直线下有多少个格点 36 38 | 综合 36 39 | 基本形 公式 37 40 | 树的计数 38 41 | 代数 39 42 | 三角公式 39 43 | 积分表 39 44 | Java IO 40 45 | Vimrc 41 46 | -------------------------------------------------------------------------------- /src/tmp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/tmp.cpp -------------------------------------------------------------------------------- /src/vimrc.vim: -------------------------------------------------------------------------------- 1 | set nu si mouse=a sw=4 ts=4 sts=4 2 | set mp=g++\ -O2\ -Wall\ --std=c++11\ -Wno-unused-result\ %:r.cpp\ -o\ %:r 3 | nmap :vs %:r.in 4 | nmap :!time ./%:r < %:r.in 5 | nmap :w :make 6 | -------------------------------------------------------------------------------- /src/三角形的心.cpp: -------------------------------------------------------------------------------- 1 | // 传入的参数 point a,b,c; 三角形顶点 2 | double area(point a,point b,point c) { return(fabs(det(b-a,c-a))/2); }// 面积 3 | point barycenter(point a,point b,point c) // 重心 4 | { return(point((a.x+b.x+c.x)/3.0,(a.y+b.y+c.y)/3.0)); } 5 | point orthocenter(point a,point b,point c) // 垂心 6 | { double dx,dy,d=(c.x-b.x)*(c.y-a.y)-(c.x-a.x)*(c.y-b.y); 7 | dx=(a.y*(c.y-b.y)+a.x*(c.x-b.x))*(c.y-a.y)-(b.y*(c.y-a.y)+b.x*(c.x-a.x))*(c.y-b.y); 8 | dy=(c.x-b.x)*(b.y*(c.y-a.y)+b.x*(c.x-a.x))-(c.x-a.x)*(a.y*(c.y-b.y)+a.x*(c.x-b.x)); 9 | return(point(dx/d,dy/d)); 10 | } 11 | point circumcenter(point a,point b,point c) {// 外心,直角三角形须特判 12 | double A=dist(b,c),B=dist(a,c),C=dist(a,b); 13 | double P=(SQR(A)+SQR(B)+SQR(C))/2.0; 14 | double Q=1.0/(1/(P-SQR(A))+1/(P-SQR(B))+1/(P-SQR(C))); 15 | double R=sqrt(P-Q)/2; //R 为外接圆半径,需要时可用,否则可删去 16 | double d1=Q/(P-SQR(A)),d2=Q/(P-SQR(B)),d3=Q/(P-SQR(C)); 17 | return((1-d1)/2.0*a+(1-d2)/2.0*b+(1-d3)/2.0*c); 18 | } 19 | point incenter(point a,point b,point c) { 20 | double A=dist(b,c),B=dist(a,c),C=dist(a,b); 21 | double r=2*area(a,b,c)/(A+B+C); //r 为内切圆半径,需要时可用,否则可删去 22 | return(point((A*a.x+B*b.x+C*c.x)/(A+B+C),(A*a.y+B*b.y+C*c.y)/(A+B+C))); 23 | } 24 | -------------------------------------------------------------------------------- /src/二次剩余.cpp: -------------------------------------------------------------------------------- 1 | void calcH(int &t, int &h, const int p) { 2 | int tmp = p - 1; for (t = 0; (tmp & 1) == 0; tmp /= 2) t++; h = tmp; 3 | } 4 | // solve equation x^2 mod p = a 5 | bool solve(int a, int p, int &x, int &y) { 6 | srand(19920225); 7 | if (p == 2) { x = y = 1; return true; } 8 | int p2 = p / 2, tmp = power(a, p2, p); 9 | if (tmp == p - 1) return false; 10 | if ((p + 1) % 4 == 0) { 11 | x = power(a, (p + 1) / 4, p); y = p - x; return true; 12 | } else { 13 | int t, h, b, pb; calcH(t, h, p); 14 | if (t >= 2) { 15 | do {b = rand() % (p - 2) + 2; 16 | } while (power(b, p / 2, p) != p - 1); 17 | pb = power(b, h, p); 18 | } int s = power(a, h / 2, p); 19 | for (int step = 2; step <= t; step++) { 20 | int ss = (((long long)(s * s) % p) * a) % p; 21 | for (int i = 0; i < t - step; i++) ss = ((long long)ss * ss) % p; 22 | if (ss + 1 == p) s = (s * pb) % p; pb = ((long long)pb * pb) % p; 23 | } x = ((long long)s * a) % p; y = p - x; 24 | } return true; 25 | } 26 | -------------------------------------------------------------------------------- /src/二维集合续.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | } -------------------------------------------------------------------------------- /src/后缀数组(nlogn).cpp: -------------------------------------------------------------------------------- 1 | int rank[MAX_N],height[MAX_N]; 2 | int cmp(int *x,int a,int b,int d){ 3 | return x[a]==x[b]&&x[a+d]==x[b+d]; 4 | } 5 | void doubling(int *a,int N,int M){ 6 | static int sRank[MAX_N],tmpA[MAX_N],tmpB[MAX_N]; 7 | int *x=tmpA,*y=tmpB; 8 | for(int i=0;i=0;--i) sa[--sRank[x[i]]]=i; 12 | for(int d=1,p=0;p=d) y[p++]=sa[i]-d; 15 | for(int i=0;i=0;--i) sa[--sRank[x[y[i]]]]=y[i]; 19 | swap(x,y); x[sa[0]]=0; p=1; 20 | for(int i=1;ilength+1); 12 | while(p!=NULL&&p->go[token]==NULL) 13 | p->go[token]=np, p=p->parent; 14 | if(p==NULL) np->parent=start; 15 | else{ 16 | State *q=p->go[token]; 17 | if(p->length+1==q->length) np->parent=q; 18 | else{ 19 | State *nq=new(tot_node++) State(p->length+1); 20 | memcpy(nq->go,q->go,sizeof(q->go)); 21 | nq->parent=q->parent; 22 | np->parent=q->parent=nq; 23 | while(p!=NULL&&p->go[token]==q) 24 | p->go[token]=nq, p=p->parent; 25 | } 26 | } 27 | return np; 28 | } 29 | -------------------------------------------------------------------------------- /src/启发式分解.cpp: -------------------------------------------------------------------------------- 1 | int ansn; LL ans[1000]; 2 | LL func(LL x,LL n){ return(mod_mul(x,x,n)+1)%n; } 3 | LL Pollard(LL n){ 4 | LL i,x,y,p; 5 | if(Rabin_Miller(n)) return n; 6 | if(!(n&1)) return 2; 7 | for(i=1;i<20;i++){ 8 | x=i; y=func(x,n); p=gcd(y-x,n); 9 | while(p==1) {x=func(x,n); y=func(func(y,n),n); p=gcd((y-x+n)%n,n)%n;} 10 | if(p==0||p==n) continue; 11 | return p; 12 | } 13 | } 14 | void factor(LL n){ 15 | LL x; 16 | x=Pollard(n); 17 | if(x==n){ ans[ansn++]=x; return; } 18 | factor(x), factor(n/x); 19 | } -------------------------------------------------------------------------------- /src/回文串manacher.cpp: -------------------------------------------------------------------------------- 1 | for(int i=1,j=0;i!=(n<<1)-1;++i){ 2 | int p=i>>1,q=i-p,r=((j+1)>>1)+l[j]-1; 3 | l[i]=rr) j=i; 6 | a+=l[i]; 7 | } 8 | -------------------------------------------------------------------------------- /src/图同构Hash.tex: -------------------------------------------------------------------------------- 1 | 2 | $$F_t(i) = 3 | (F_{t-1}(i) \times A + 4 | \sum_{i\rightarrow j} F_{t-1}(j) \times B + 5 | \sum_{j\rightarrow i} F_{t-1}(j) \times C + 6 | D \times (i = a))\ mod\ P 7 | $$ 8 | 9 | 枚举点 a , 迭代 K 次后求得的就是 a 点所对应的 hash 值 10 | 11 | 其中 K , A , B , C , D , P 为 hash 参数 , 可自选 12 | -------------------------------------------------------------------------------- /src/字符串最小表示.cpp: -------------------------------------------------------------------------------- 1 | std::string find(std::string s) { 2 | int i,j,k,l,N=s.length(); s+=s; 3 | for(i=0,j=1;j=N) break; 6 | if(s[i+k] 1){ 14 | for(i=1;i mm){ mm=len[seq[i]]; k=i; } 18 | for(i=1;i mm) 25 | mm=len[seq[j]], k=j; 26 | } 27 | sum=0; 28 | for(i=0;ians) ans=size, found=true; return; 7 | } for (int k=0,i,j; k1 && (conv[totco-1]-conv[totco-2])/(p[i]-conv[totco-2])<=0 ) totco--; 9 | conv[totco++]=p[i]; 10 | } 11 | int limit=totco; 12 | for ( int i=n-1; i>=0; i-- ){ 13 | while ( totco>limit && (conv[totco-1]-conv[totco-2])/(p[i]-conv[totco-2])<=0 ) totco--; 14 | conv[totco++]=p[i]; 15 | } 16 | } 17 | point pp[100000]; 18 | int main(){ 19 | scanf("%d", &n); 20 | for ( int i=0; i0 ) now++; 33 | if ( dist( pp[i], pp[now] )>ans ) ans=dist( pp[i], pp[now] ); 34 | if ( dist( pp[i+1], pp[now] )>ans ) ans=dist( pp[i+1], pp[now] ); 35 | } 36 | printf("%d\n", ans); 37 | } 38 | -------------------------------------------------------------------------------- /src/极大团计数.cpp: -------------------------------------------------------------------------------- 1 | //Bool g[][] 为图的邻接矩阵,图点的标号由 1 至 n 2 | void dfs(int size){ 3 | int i, j, k, t, cnt, best = 0; 4 | if (ne[size]==ce[size]){ if (ce[size]==0) ++ans; return; } 5 | for (t=0, i=1; i<=ne[size]; ++i) { 6 | for (cnt=0, j=ne[size]+1; j<=ce[size]; ++j) 7 | if (!g[list[size][i]][list[size][j]]) ++cnt; 8 | if (t==0 || cnt0){ for (i=k; i<=ce[size]; ++i) 12 | if (!g[list[size][t]][list[size][i]]) break; 13 | swap(list[size][k], list[size][i]); 14 | } i=list[size][k]; ne[size+1]=ce[size+1]=0; 15 | for (j=1; j0$ 2 | LL solve(LL n,LL a,LL b,LL m){ 3 | if(b==0) return n*(a/m); 4 | if(a>=m) return n*(a/m)+solve(n,a%m,b,m); 5 | if(b>=m) return (n-1)*n/2*(b/m)+solve(n,a,b%m,m); 6 | return solve((a+b*n)/m,(a+b*n)%m,m,b); 7 | } 8 | -------------------------------------------------------------------------------- /src/积分表.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand*\HyPL@Entry[1]{} 18 | \HyPL@Entry{0<>} 19 | -------------------------------------------------------------------------------- /src/积分表.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/积分表.out -------------------------------------------------------------------------------- /src/积分表.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FTRobbin/Dreadnought-Standard-Code-Library/11c861e55a73be9c32a799bfe4398e0c62c2da15/src/积分表.pdf -------------------------------------------------------------------------------- /src/素数判定.cpp: -------------------------------------------------------------------------------- 1 | int strong_pseudo_primetest(long long n,int base) { 2 | long long n2=n-1,res; 3 | int s=0; 4 | while(n2%2==0) n2>>=1,s++; 5 | res=powmod(base,n2,n); 6 | if((res==1)||(res==n-1)) return 1; 7 | s--; 8 | while(s>=0) { 9 | res=mulmod(res,res,n); 10 | if(res==n-1) return 1; 11 | s--; 12 | } 13 | return 0; // n is not a strong pseudo prime 14 | } 15 | int isprime(long long n) { 16 | static LL testNum[]={2,3,5,7,11,13,17,19,23,29,31,37}; 17 | static LL lim[]={4,0,1373653LL,25326001LL,25000000000LL,2152302898747LL, 3474749660383LL,341550071728321LL,0,0,0,0}; 18 | if(n<2||n==3215031751LL) return 0; 19 | for(int i=0;i<12;++i){ 20 | if(n VD; 3 | VD simplex(vector A, VD b, VD c) { 4 | int n = A.size(), m = A[0].size() + 1, r = n, s = m - 1; 5 | vector D(n + 2, VD(m + 1, 0)); vector ix(n + m); 6 | for (int i = 0; i < n + m; ++ i) ix[i] = i; 7 | for (int i = 0; i < n; ++ i) { 8 | for (int j = 0; j < m - 1; ++ j) D[i][j] = -A[i][j]; 9 | D[i][m - 1] = 1; D[i][m] = b[i]; 10 | if (D[r][m] > D[i][m]) r = i; 11 | } 12 | for (int j = 0; j < m - 1; ++ j) D[n][j] = c[j]; 13 | D[n + 1][m - 1] = -1; 14 | for (double d; ; ) { 15 | if (r < n) { 16 | int t = ix[s]; ix[s] = ix[r + m]; ix[r + m] = t; 17 | D[r][s] = 1.0 / D[r][s]; vector speedUp; 18 | for (int j = 0; j <= m; ++ j) if (j != s) { 19 | D[r][j] *= -D[r][s]; 20 | if(D[r][j]) speedUp.push_back(j); 21 | } 22 | for (int i = 0; i <= n + 1; ++ i) if (i != r) { 23 | for(int j = 0; j < speedUp.size(); ++ j) 24 | D[i][speedUp[j]] += D[r][speedUp[j]] * D[i][s]; 25 | D[i][s] *= D[r][s]; 26 | }} r = -1; s = -1; 27 | for (int j = 0; j < m; ++ j) if (s < 0 || ix[s] > ix[j]) 28 | if (D[n + 1][j] > EPS || (D[n + 1][j] > -EPS && D[n][j] > EPS)) s = j; 29 | if (s < 0) break; 30 | for (int i = 0; i < n; ++ i) if (D[i][s] < -EPS) 31 | if (r < 0 || (d = D[r][m] / D[r][s] - D[i][m] / D[i][s]) < -EPS 32 | || (d < EPS && ix[r + m] > ix[i + m])) r = i; 33 | if (r < 0) return VD(); // 无边界 34 | } 35 | if (D[n + 1][m] < -EPS) return VD(); // 无解 36 | VD x(m - 1); 37 | for (int i = m; i < n + m; ++ i) if (ix[i] < m - 1) x[ix[i]] = D[i - m][m]; 38 | return x; // 最优值在 D[n][m] 39 | } 40 | -------------------------------------------------------------------------------- /src/经纬度求球面最短距离.cpp: -------------------------------------------------------------------------------- 1 | double sphereDis(double lon1, double lat1, double lon2, double lat2, double R) { 2 | return R * acos(cos(lat1) * cos(lat2) * cos(lon1 - lon2) + sin(lat1) * sin(lat2)); 3 | } 4 | -------------------------------------------------------------------------------- /src/蔡勒公式.cpp: -------------------------------------------------------------------------------- 1 | int zeller(int y,int m,int d) { 2 | if (m<=2) y--,m+=12; int c=y/100; y%=100; 3 | int w=((c>>2)-(c<<1)+y+(y>>2)+(13*(m+1)/5)+d-1)%7; 4 | if (w<0) w+=7; return(w); 5 | } 6 | -------------------------------------------------------------------------------- /src/轻重链剖分.cpp: -------------------------------------------------------------------------------- 1 | struct Tree(){}*root[N]; 2 | int father[N],size[N],depth[N]; 3 | int bfsOrd[N],pathId[N],ordInPath[N],sqn[N]; 4 | void doBfs(int s){ 5 | int qh=0,qt=0,*que=bfsOrd; father[s]=-1; depth[s]=0; 6 | for(que[qt++]=s;qh=0;--i){ 16 | int u=bfsOrd[i]; size[u]=1; 17 | foreach(iter,adj[u]){ 18 | int v=*iter; if(v==father[u]) continue; size[u]+=size[v]; 19 | } 20 | } 21 | memset(pathId,-1,sizeof pathId); 22 | for(int i=0;i=0 && i< 2) turn(i+1, j, x0+L+z, y, x0+L-x, x0+L, y0, H, W, L); 6 | if(j>=0 && j< 2) turn(i, j+1, x, y0+W+z, y0+W-y, x0, y0+W, L, H, W); 7 | if(i<=0 && i>-2) turn(i-1, j, x0-z, y, x-x0, x0-H, y0, H, W, L); 8 | if(j<=0 && j>-2) turn(i, j-1, x, y0-z, y-y0, x0, y0-H, L, H, W); 9 | } 10 | } 11 | int main(){ 12 | int L, H, W, x1, y1, z1, x2, y2, z2; 13 | cin >> L >> W >> H >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 14 | if (z1!=0 && z1!=H) if (y1==0 || y1==W) 15 | swap(y1,z1), std::swap(y2,z2), std::swap(W,H); 16 | else swap(x1,z1), std::swap(x2,z2), std::swap(L,H); 17 | if (z1==H) z1=0, z2=H-z2; 18 | r=0x3fffffff; 19 | turn(0,0,x2-x1,y2-y1,z2,-x1,-y1,L,W,H); 20 | cout<