跳到正文

个人记录

非常有用的东西

DSD486约 72 分钟
原文
文章信息与版本

文章信息

发布
2026年7月31日
收录
2026年8月5日
更新
2026年8月16日
篇幅
约 72 分钟

版本

  1. v1当前

清华大学组合数课程

https://oi.wiki/graph/mst/#boruvka-%E7%AE%97%E6%B3%95

Nim游戏

https://oi.wiki/math/combinatorics/stirling/

代码
-std=c++14 -Wl,--stack,268435456
C++
#include<bits/stdc++.h>
#define int long long
#define PII pair <int, int> 
using namespace std;
bool bbb;

bool eee;
signed main() {
	cerr << (&eee - &bbb) / 1024.0 / 1024 << '\n';
	ios :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	return 0;
}
代码
echo off
:loop
data.exe
t.exe
force.exe
fc t.out force.out
if errorlevel 1 pause
goto loop
C++
#include<bits/stdc++.h>
#define int long long
#define PII pair <int, int>
using namespace std;

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	while(1) {
		system("data.exe");
		system("t.exe");
		system("std.exe");
		if(system("fc t.out std.out")) return 0;
	}
	return 0;
}

反演

https://oi-wiki.org/math/number-theory/basic/#%E5%8F%96%E6%95%B4%E5%87%BD%E6%95%B0

NOI大纲

Graph Editor

FFT

横坐标是连续整数的 Lagrange 插值

Alt+42689α

C++
fact_inv[i] = fact_inv[i - 1] * i % mod;

fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
C++
★
//vector 去重方法
	vector <int> v;
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

link 是关键字
(int)v.size()
主函数外不要定义 x, y

C++
★
bool 类型的自增运算(++):对 bool 变量使用 ++x 或 x++ 现在是语法错误(此前在 C++14 中虽已弃用但仍可编译)。

★
如果二分的范围中有负数,那么(l+r)/2是否会错?

整数除法行为?:在 C++、Java 等语言中,(l + r) / 2 对负数是?向零取整?(如 (-5 + 2) / 2 = -1),而数学期望的“下取整中点”可能是 -2,导致区间收缩方向异常。
?死循环风险?:若边界更新用 l = mid 且 mid 计算偏高(如 l=-1, r=0 时 mid = -1),可能无限循环。

★
unqiue(a + 1, a + n + 1, cmp);
这里的 cmp 是比较等于的自定义函数。
复制时注意删掉 cmp ,不会报错。

★
int u = q.top().p, udis = q.top().dis;
q.pop();
if(udis > dis[u]) continue;
Dijkstra不加这句话复杂度就是假的

★
const long long M = 1e17 + 5;
会引发精度问题,大型比赛建议写成
const long long M = 100000000000000005;
或
const long long M = 1e17l + 5;         //long double 只支持到18为左右,慎用!

★
set结构体自定义排序方法:
struct Node {
	int x, y;
} ;
struct Node_cmp {		//仿函数
	bool operator() (const Node &A, const Node &B) const { return A.x < B.x; }
};
set <Node, Node_cmp> st;
注意:这样有个潜在问题,如果有两个元素 x 相同而 y 不同,那么 set 是不会放进去第二个元素的!
一定要保证所有元素两两都是大于或小于的!

pb_ds 入门到入土:https://www.cnblogs.com/redacted-area/p/18063265

https://paintboard.ikale.io/

https://www.bilibili.com/video/BV1i5NneQEEL/

https://www.koalastothemax.com/?aHR0cHM6Ly9jZG4ubHVvZ3UuY29tLmNuL3VwbG9hZC91c2VyaWNvbi8xMDQwMzUzLnBuZw==

OI大事记:https://www.luogu.com.cn/paste/n2j52cs0

讲反演的好博客:https://www.luogu.me/article/998kttnc

关于 pollard-rho: https://www.luogu.com.cn/discuss/987299 https://www.luogu.com.cn/article/ezjcoth4

平衡树单log启发式合并的trick:https://www.luogu.me/article/jnfozglu

有可能你这辈子打的广义SAM都是错的:https://www.luogu.com.cn/discuss/322224

复杂度分析AI:https://www.timecomplexity.ai/

很好的讲SATT的文章:https://f7487.blog.uoj.ac/blog/7490

合成:https://craft.murasame.site/

一些搬运脚本的博客:https://www.cnblogs.com/Wy-x/articles/19019167

原题机:https://cpret.online/ https://yuantiji.ac https://chat.cpgraph.top/

工具箱

主页2

『』「」<>《》【】{}()[]

置顶:

好活共赏

小恐龙:chrome://dino

1、然后输入以下代码,恐龙将变得无敌:Runner.instance_.gameOver=function(){}

2、下面是急速快跑代码,参数可修改:Runner.instance_.setSpeed(20)

3、下面是跳高代码,参数可修:Runner.instance_.tRex.setJumpVelocity(20)

接入DeepSeek-R1的平台信息汇总

GitCode AI

HIX AI

AkashChat

reddit

SambaNova Cloud

小艺

知乎直达

腾讯元宝

koyso.com

KaTeX\KaTeX

stylus

临时邮箱

原题机

数学工具箱

c++压行机

关于出题

你画我猜

免费临时邮箱

https://www.bilibili.com/video/BV17CYxeLEJW/

极域再见

解谜游戏

浅论 OI 中的卡常技巧

原神动漫配音

路过图床

z4a图床

图像格式转换

迎接坤老师

头图

头图2

Atcoder Better

NOI linnux

查看他人主页源码

如何将Dev-C++的GCC升级为最新版

时间复杂度分析器

学习随机数

FFT快速傅里叶变换

快速高精度进制转换

一些工具

testlib

OneDrive

下载bilibili视频

C++20 的一些特性总结

卡常技巧

pb_ds

splay

c++模拟Windows系统

人生之路游戏

丧尸危机

探险游戏

2023J组初赛视频

绳网

生成测试点数据

洛谷工具网站

极域的处刑方法

代码
-1 1000017 0 0 0 1 0 0 0 6 1 0 0 0 0 0 0 0 999985 1 28 1 0 2 0 0 1
 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

丧尸围城存档

工具 TOOLS\texttt{{\large \color{52C41A}工具 TOOLS}}

洛谷脚本 LUOGU SCRIPTS\texttt{{\large \color{52C41A}洛谷脚本 LUOGU SCRIPTS}}

做题相关 ABOUT PROBELMS\texttt{{\large \color{52C41A}做题相关 ABOUT PROBELMS}}

有用的网站 USEFUL WEBSIDES\texttt{{\large \color{52C41A}有用的网站 USEFUL WEBSIDES}}

资料 MATERIALS\texttt{{\large \color{52C41A}资料 MATERIALS}}

摸鱼 FISHING\texttt{{\large \color{52C41A}摸鱼 FISHING}}

迷惑代码合集\texttt{{\color{8E44AD}迷惑代码合集}}:迷惑代码合集/CSP2021迷惑代码合集/上海 CSP-S 组奇葩代码合集/cz的A+B题解/NOIP2021代码合集/对不起这里才是NOIP2021代码合集

测试 TESTS\texttt{{\large \color{52C41A}测试 TESTS}}

游戏 GAMES\texttt{{\large \color{52C41A}游戏 GAMES}}

颜色十六进制RGB值颜色十六进制RGB值AC绿52C41A(82,196,26)入门红FE4C61(254,76,97)WA红E74C3C(231,76,60)普及-橙F39C11(243,156,17)RE紫9D3DCF(157,61,207)普及黄FFC116(255,193,22)CE黄FADB14(250,219,20)普及+提高 绿52C41A(82,196,26)TLE黑052242(5,34,66)提高+省选-蓝3498DB(52,152,219)MLE黑052242(5,34,66)省选紫9D3DCF(157,61,207)OLE黑052242(5,34,66)NOI黑0E1D69(14,39,105)UKE蓝0E1D69(14,29,105)未评定灰BFBFBF(191,191,191)紫名8E44AD(142,68,173)排行绿52C41A(82,196,26)红名E74C3C(231,76,60)排行橙F39C11(243,156,17)橙名E67E22(230,126,34)排行黄FADB14(250,219,20)绿名5EB95E(94,185,94)排行红E74C3C(231,76,60)蓝名0E90D2(14,144,210)通过钩绿52C41A(82,196,26)灰名BFBFBF(191,191,191)不通过叉红E74C3C(231,76,60)吉利红E74C3C(231,76,60)官方比赛红E74C3C(231,76,60)中平绿5EB95E(94,185,94)团队比赛绿054310(5,67,16)凶兆黑000000(0,0,0)个人比赛蓝3498DB(52,152,219)ACM制紫8E44AD(142,68,173)Rated绿5EB95E(94,185,94)IOI制黄F1C40F(241,196,15)未开始绿5EB95E(94,185,94)乐多制黄F1C40F(241,196,15)已结束红E74C3C(231,76,60)OI制橙F39C11(243,156,17)进行中*4290D8(66,144,216)背景灰EFEFEF(239, 239, 239)小字灰7F7F7F(127,127,127)按钮蓝0E90D2(14,144,210)链接蓝3498DB(52,152,219)按钮红DD514C(221,81,76)通过率蓝3498DB(52,152,219)金钩黄FFE169(255,225,105)背景粉F5CECD(245,206,205)绿钩绿5EB95E(94,185,94)背景绿C9E7C9(201,231,201)蓝钩蓝3498DB(52,152,219)背景蓝CAEBFB(202,235,251)题目来源蓝3498DB(52,152,219)灰色7F7F7F(127,127,127)题目算法红E74C3C(231,76,60)白色FFFFFF(255,255,255)题目地点绿52C41A(82,196,26)黑色000000(0,0,0)\def\arraystretch{1.2} \begin{array}{|c|l|l||c|l|l|} \hline 颜色 & 十六进制 & RGB值 & 颜色 & 十六进制 & RGB值 \\ \hline \color{#52C41A}\text{AC绿} & \text{52C41A} & \text{(82,196,26)} & \color{#FE4C61}\text{入门红} & \text{FE4C61} & \text{(254,76,97)} \\ \hline \color{#E74C3C}\text{WA红} & \text{E74C3C} & \text{(231,76,60)} & \color{#F39C11}\text{普及-橙} & \text{F39C11} & \text{(243,156,17)} \\ \hline \color{#9D3DCF}\text{RE紫} & \text{9D3DCF} & \text{(157,61,207)} & \color{#FFC116}\text{普及黄} & \text{FFC116} & \text{(255,193,22)}\\ \hline \color{#FADB14}\text{CE黄} & \text{FADB14} & \text{(250,219,20)} & \color{#52C41A}\text{普及+提高 绿} & \text{52C41A} & \text{(82,196,26)} \\ \hline \color{#052242}\text{TLE黑} & \text{052242} & \text{(5,34,66)} & \color{#3498DB}\text{提高+省选-蓝} & \text{3498DB} & \text{(52,152,219)} \\ \hline \color{#052242}\text{MLE黑} & \text{052242} & \text{(5,34,66)} & \color{#9D3DCF}\text{省选紫} & \text{9D3DCF} & \text{(157,61,207)} \\ \hline \color{#052242}\text{OLE黑} & \text{052242} & \text{(5,34,66)} & \color{#0E1D69}\text{NOI黑} & \text{0E1D69} & \text{(14,39,105)} \\ \hline \color{#0E1D69}\text{UKE蓝} & \text{0E1D69} & \text{(14,29,105)} & \color{#BFBFBF}\text{未评定灰} & \text{BFBFBF} & \text{(191,191,191)} \\ \hline \hline \color{#8E44AD}\text{紫名} & \text{8E44AD} & \text{(142,68,173)} & \color{#52C41A}\text{排行绿} & \text{52C41A} & \text{(82,196,26)} \\ \hline \color{#E74C3C}\text{红名} & \text{E74C3C} & \text{(231,76,60)} & \color{#F39C11}\text{排行橙} & \text{F39C11} & \text{(243,156,17)} \\ \hline \color{#E67E22}\text{橙名} & \text{E67E22} & \text{(230,126,34)} & \color{#FADB14}\text{排行黄} & \text{FADB14} & \text{(250,219,20)} \\ \hline \color{#5EB95E}\text{绿名} & \text{5EB95E} & \text{(94,185,94)} & \color{#E74C3C}\text{排行红} & \text{E74C3C} & \text{(231,76,60)}\\ \hline \color{#0E90D2}\text{蓝名} & \text{0E90D2} & \text{(14,144,210)} & \color{#52C41A}\text{通过钩绿} & \text{52C41A} & \text{(82,196,26)} \\ \hline \color{#BFBFBF}\text{灰名} & \text{BFBFBF} & \text{(191,191,191)} & \color{#E74C3C}\text{不通过叉红} & \text{E74C3C} & \text{(231,76,60)} \\ \hline \hline \color{#E74C3C}\text{吉利红} & \text{E74C3C} & \text{(231,76,60)} & \color{#E74C3C}\text{官方比赛红} & \text{E74C3C} & \text{(231,76,60)} \\ \hline \color{#5EB95E}\text{中平绿} & \text{5EB95E} & \text{(94,185,94)} & \color{#054310}\text{团队比赛绿} & \text{054310} & \text{(5,67,16)} \\ \hline \color{#000000}\text{凶兆黑} & \text{000000} & \text{(0,0,0)} & \color{#3498DB}\text{个人比赛蓝} & \text{3498DB} & \text{(52,152,219)} \\ \hline \hline \color{#8E44AD}\text{ACM制紫} & \text{8E44AD} & \text{(142,68,173)} & \color{#5EB95E}\text{Rated绿} & \text{5EB95E} & \text{(94,185,94)} \\ \hline \color{#F1C40F}\text{IOI制黄} & \text{F1C40F} & \text{(241,196,15)} & \color{#5EB95E}\text{未开始绿} & \text{5EB95E} & \text{(94,185,94)} \\ \hline \color{#F1C40F}\text{乐多制黄} & \text{F1C40F} & \text{(241,196,15)} & \color{#E74C3C}\text{已结束红} & \text{E74C3C} & \text{(231,76,60)} \\ \hline \color{#F39C11}\text{OI制橙} & \text{F39C11} & \text{(243,156,17)} & \color{#4290D8}\text{进行中*} & \text{4290D8} & \text{(66,144,216)} \\ \hline \hline \color{#EFEFEF}\text{背景灰} & \text{EFEFEF} & \text{(239, 239, 239)} & \color{#7F7F7F}\text{小字灰} & \text{7F7F7F} & \text{(127,127,127)} \\ \hline \hline \color{#0E90D2}\text{按钮蓝} & \text{0E90D2} & \text{(14,144,210)} & \color{#3498DB}\text{链接蓝} & \text{3498DB} & \text{(52,152,219)} \\ \hline \color{#DD514C}\text{按钮红} & \text{DD514C} & \text{(221,81,76)} & \color{#3498DB}\text{通过率蓝} & \text{3498DB} & \text{(52,152,219)} \\ \hline \hline \color{#FFE169}\text{金钩黄} & \text{FFE169} & \text{(255,225,105)} & \color{#F5CECD}\text{背景粉} & \text{F5CECD} & \text{(245,206,205)} \\ \hline \color{#5EB95E}\text{绿钩绿} & \text{5EB95E} & \text{(94,185,94)} & \color{#C9E7C9}\text{背景绿} & \text{C9E7C9} & \text{(201,231,201)} \\ \hline \color{#3498DB}\text{蓝钩蓝} & \text{3498DB} & \text{(52,152,219)} & \color{#CAEBFB}\text{背景蓝} & \text{CAEBFB} & \text{(202,235,251)} \\ \hline \hline \color{#3498DB}\text{题目来源蓝} & \text{3498DB} & \text{(52,152,219)} &\color{#7F7F7F}\text{灰色} & \text{7F7F7F} & \text{(127,127,127)} \\ \hline \color{#E74C3C}\text{题目算法红} & \text{E74C3C} & \text{(231,76,60)}& \color{#FFFFFF}\text{白色} & \text{FFFFFF} & \text{(255,255,255)} \\ \hline \color{#52C41A}\text{题目地点绿} & \text{52C41A} & \text{(82,196,26)}& \color{#000000}\text{黑色} & \text{000000} & \text{(0,0,0)} \\ \hline \end{array}

好

latex编辑器

outlook

如何干爆旁边人的心态

洛谷词典

快读快输

C++
void read(__int128 &x){ 
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
void print(__int128 x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

https://www.cnblogs.com/HaneDaCafe/p/18409847 或者搜 cyaron 要做的题

AT_kupc2012pr_1 AT_abc287_e B3717 CF38B CF11B CF2A P1019 P1020 P1025 P1026 P1033 P1037 P1058 P1061 P1065 P1076 P1077 P1090 P1091 P1095 P1096 P1135 P1140 P1142 P1158 P1168 P1180 P1188 P1199 P1230 P1233 P1239 P1289 P1290 P1292 P1309 P1434 P1443 P1469 P1531 P1590 P1727 P1746 P1775 P1853 P1865 P1908 P1920 P1932 P1965 P1970 P2005 P2078 P2082 P2181 P2239 P2367 P2280 P2357 P2397 P2440 P3951 P2678 P2719 P2712 P3372 P3375 P3368 P3150 P2580 P3353 P3811 P3903 P4549 P4779 P5635 P1923 P4715 P7318 P7074 P7471 P7910 P7912 P7911 P8306 P9498 P9504 P9473 P9457

输入输出加速:关闭同步流

C++
ios::sync_with_stdio(false);
cin.tie(0);

高精度

C++
struct Bight{
	int len,a[maxn];
	Bight(int x=0){
		memset(a,0,sizeof(a));
		for(len=1;x;len++) a[len]=x%10,x/=10;
		len--;
	}
	int &operator[](int i){
		return a[i];
	}
	void flatten(int L){//展平 
		len=L;
		for(int i=1;i<=len;i++) a[i+1]+=a[i]/10,a[i]%=10;
		for(;!a[len];) len--;
	}
	void print(){//输出 
		for(int i=max(len,1);i>=1;i--) cout<<a[i];
	}
};
Bight operator+(Bight a,Bight b){
	Bight c;
	int len=max(a.len,b.len);
	for(int i=1;i<=len;i++) c[i]+=a[i]+b[i];
	c.flatten(len+1);
	return c;
}
Bight operator*(Bight a,int b){
	Bight c;
	int len=a.len;
	for(int i=1;i<=len;i++) c[i]=a[i]*b;
	c.flatten(len+11);
	return c;
}

二分

二分答案(枚举答案,进行验证)

C++
一.分析答案范围(l,r)
l:0,1  r:10的9次方
(1)题目给的范围(2)根据题意分析
二.二分  
if(函数名(mid)){
	<=mid:l=mid+1 
	==mid;ans=mid 
   	>=mid:r=mid-1
}
三.验证答案:暴力,贪心

归并排序

C++
void px(int l1,int r1,int l2,int r2){
	int i=l1,j=l2,k=l1,c[100005];
	while(i<=r1&&j<=r2){
		if(a[i]<=a[j]){
			c[k]=a[i];
			k++;
			i++;
		}
		else{
			c[k]=a[j];
   			k++;
			j++;
		}
	}
	while(i<=r1){
		c[k]=a[i];
		k++;
		i++;
	}
	while(j<=r2){
		c[k]=a[j];
		k++;
		j++;
	}
	for(i=l1;i<=r2;i++){
		a[i]=c[i];
	}
}

线性表(栈,队列,字符串)

特点

C++
首元素只有一个后继,
尾元素只有一个前驱,
其余元素有一个前驱和一个后继。

栈:先进后出

数组模拟
C++
int st[100],top=0;
(1)top==0 栈空
(2)top==99
(3)入栈:st[++top]=x;
(4)出栈:top--;
(5)获取:st[top]
模板
C++
STL-<stack>
(1)定义:stack<int>名字;
(2)入栈:名字.push(x);
(3)出栈:名字.pop();
(4)获取:名字.top();
(5)检测栈是否为空:
名字.empty(){
	空:true
	不空:false
}
单调栈
C++
for(int i=1;i<=n;i++){
	while(!st.empty()&&a[st.top()]<a[i]){
		f[st.top()]=i;
		st.pop();
	}
	st.push(i);
}

队列:先进先出

数组模拟
C++
(1)定义:int q[100],front=0,rear=-1;
(2)队空:rear+1==front;
(3)队满:rear==100;
(4)入队:q[++rear]=x;
(5)出队:front++;
(6)获取队首:q[front]
(7)获取队尾:q[rear]
(8)求元素个数:rear-front+1;
模板
C++
STL-<queue>
(1)定义:queue<int>名字;
(2)入队:名字.push(x);
(3)出队:名字.pop();
(4)获取队首:名字.front();
(5)获取队尾:名字.back();
(6)检测队列是否为空:
名字.empty(){
	空:true
	不空:false
}
(7)求元素个数:名字.size();

双端队列

模板
C++
STL-<deque>
(1)定义:deque<int>名字;
(2)入队{
	名字.push_front(x);
	名字.push_back(x);
}
(3)出队{
	名字.pop_front();
	名字.pop_back();
}
(4)获取队首:名字.front();
(5)获取队尾:名字.back();
(6)检测队列是否为空:
名字.empty(){
	空:true
	不空:false
}
(7)求元素个数:名字.size();
(8)清空:名字.clear();
单调队列
C++
for(int i=1;i<=n;i++){
	while(!t.empty()&&t.front()+k-1<i){
		t.pop_front();
	}
	while(!t.empty()&&a[t.back()]<=a[i]{
		t.pop_back();
	}
	t.push_back(i);
	if(i>=k){
		cout<<a[t.front()]<<" ";
	}
}
迭代器
C++
deque<int>::iterator it=名字;
解引用:
*名字.begin(); 首
*(--名字.end()); 尾后
*名字.rbegin();
*名字.rend();

链表

C++
struct node{
	int data,nxt;
}List[100];
头指针:int head=1;
链表长度,申请新节点:int tot=0;
(1)查找x在不在链表中?(按值查找)
for(int i=head;i!=0;i=List[i].nxt){
	if(List[i].data==x){
		return true;
	}
}
return false;
(2)查找第P个元素是什么?(按序号查找)
int s=0;
for(int i=head;i!=0;i=List[i].nxt){
	if(++s==P){
		return List[i].data;
	}
}
return -1;
(3)在头节点前面插入
List[tot].nxt=head;	
head=tot;
(4)在P节点前插入
int s=0;
for(int i=head;i!=0;i=List[i].nxt){
	if(++s==P-1){
		List[tot].nxt=List[s].nxt;
		List[s].nxt=tot;
	}
}
(5)删除链表中值为x的节点
for(int i=head;i!=0;i=List[i].nxt){
	if(List[List[i].nxt].data==x){
		List[i].nxt=List[List[i].nxt].nxt;
		break;
	}
}
(6)删除第P个节点
int s=0;
for(int i=head;i!=0;i=List[i].nxt){
	if(++s==P-1){
		List[i].nxt=List[List[i].nxt].nxt;
		break;
	}
}
(7)新建节点
List[++tot].data=x;

搜索

深度优先搜索(DFS)
C++
方向增量{
	int dx[4]={-1,0,1,0};
	int dy[4]={0,1,0,-1};
}
void dfs(int x,int y){
	if(x==fx&&y==fy){
		sum++;
		return;
	}
	for(int i=0;i<=3;i++){
		int nx=dx[i]+x;
		int ny=dy[i]+y;
		if(nx<1||nx>n||ny<1||ny>m){
			continue;
		}
		if(q[nx][ny]==1){
			continue;
		}
		if(f[nx][ny]==1){
			continue;
		}
		f[nx][ny]=1;
		dfs(nx,ny);
		f[nx][ny]=0;
	}
}
广度优先搜索(BFS)
C++
方向增量{
	int dx[4]={-1,0,1,0};
	int dy[4]={0,1,0,-1};
}
void bfs(int x,int y){
	f[x][y]=1;
	a[x][y]=0;
	sx.push(x);
	sy.push(y);
	while(!sx.empty()){
		int fx=sx.front();
		int fy=sy.front();
		sx.pop();
		sy.pop();
		for(int i=0;i<4;i++){
			int nx=fx+dx[i];
			int ny=fy+dy[i];
			if(nx<=0||nx>n||ny<=0||ny>m||f[nx][ny]==1){
				continue;
			}
			f[nx][ny]=1;
			a[nx][ny]=a[fx][fy]+1;
			sx.push(nx);
			sy.push(ny);
		}
	}
}

树和图

堆(代码为最小堆)
C++
void up(int p){
	while(p>1&&a[p]<a[p/2]){
		swap(a[p],a[p/2]);
		p/=2;
	} 
}
void down(int p){
	int s=p*2;
	while(s<=top){
		if(s+1<=top&&a[s]>a[s+1]){
			s++;
		}
		if(a[p]>a[s]){
			swap(a[p],a[s]);
			p=s;
			s*=2;
		}
		else{
			break;
		}
	}
}
void sc(int p){
	swap(a[p],a[top]);
	top--;
	up(p);
	down(p);
}
链式前向星
C++
//添加一条从u指向v的有向边 
void f(int u,int v){
	//申请新结点 
	tot++;
	a[tot].to=v;
	//头插法建立新链表 
	a[tot].next=head[u];
	head[u]=tot;
}

素数筛

埃氏筛
C++
int main(){
	cin>>n;
	cout<<2<<"\n";
	for(int j=2;j<=n/2;j++){
		f[2*j]=1;
	}
	for(int i=3;i<=n;i+=2){
		if(f[i]){
			continue;
		}
		cout<<i<<"\n";
		for(int j=i;j<=n/i;j++){
			f[i*j]=1;
		}
	}
	return 0;
}

动态规划

求最长上升子序列
C++
for(int i=1;i<=n;i++){
	dp[i]=1;
}
for(int i=1;i<=n;i++){
	ma=0;
	for(int j=1;j<i;j++){
		if(a[j]<a[i]){
			ma=max(dp[j],ma);
		}
	}
	dp[i]=ma+1;
	m=max(m,dp[i]);
}
最大子段和
C++
for(int i=1;i<=n;i++){
	dp[i]=max(a[i],a[i]+dp[i-1]);
	m=max(m,dp[i]);
}
求最长公共子序列
C++
for(int i=1;i<=m;i++){
	for(int j=1;j<=m;j++){
		if(a[i]==b[j]){
			dp[i][j]=dp[i-1][j-1]+1;
		}
		else{
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
		m=max(m,dp[i][j]);
	}
}
01背包
C++
for(int i=1;i<=n;i++){
	for(int j=m;j>=w[i];j--){
		f[j]=max(f[j],f[j-w[i]]+z[i]);
	}
}
完全背包
C++
for(int i=1;i<=m;i++){
	for(int j=w[i];j<=m;j++){	
		f[j]=max(f[j],f[j-w[i]]+z[i]);
	}
}
多重背包
C++
for(int i=1;i<=n;i++){
	for(int j=s;j>=w[i];j--){
		for(int k=1;k<=a[i];k++){
			f[j]=max(f[j],f[j-k*w[i]]*k);
		}
	}
}

快速幂

递归
C++
int f(int a,int b){
	if(b==1){
		return a;
	}
	int t=f(a,b>>1);
	t%=p;
	t*=t;
	t%=p;
	if(b&1){
		t*=a;
	}
	return t%p;
}
循环
C++
while(b){
	if(b&1){
		s*=k;
		s%=p;
	}
	k*=k;
  	k%=p;
	b>>=1;
}

http://noi.openjudge.cn/

原文