vscode 用户代码片段 c++ 模板

自己平时写题目用的几个模板,慢慢整理吧。

发现之前的自动生成网站失效了,换一个。 

推荐一个代码片段自动生成网站:snippet generator (snippet-generator.app)

模板书写规则:

// "Print to console": {                        // 代码片段名字
	// 	"scope": "javascript,typescript",       // 没用过,好像不需要用到
	// 	"prefix": "log",                        // 代码片段缩写
	// 	"body": [                               // 内容
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"  // 代码片段内容的描述、解释
	// }

头文件、宏定义编写:

"start_cpp": {
		"prefix": "start_cpp",
		"body": [
			"/*",
			"⣿⣆⠱⣝⡵⣝⢅⠙⣿⢕⢕⢕⢕⢝⣥⢒⠅⣿⣿⣿⡿⣳⣌⠪⡪⣡⢑",
			"⣿⣿⣦⠹⣳⣳⣕⢅⠈⢗⢕⢕⢕⢕⢕⢈⢆⠟⠋⠉⠁⠉⠉⠁⠈⠼⢐",
			"⢰⣶⣶⣦⣝⢝⢕⢕⠅⡆⢕⢕⢕⢕⢕⣴⠏⣠⡶⠛⡉⡉⡛⢶⣦⡀⠐",
			"⡄⢻⢟⣿⣿⣷⣕⣕⣅⣿⣔⣕⣵⣵⣿⣿⢠⣿⢠⣮⡈⣌⠨⠅⠹⣷⡀",
			"⡵⠟⠈⢀⣀⣀⡀⠉⢿⣿⣿⣿⣿⣿⣿⣿⣼⣿⢈⡋⠴⢿⡟⣡⡇⣿⡇",
			"⠁⣠⣾⠟⡉⡉⡉⠻⣦⣻⣿⣿⣿⣿⣿⣿⣿⣿⣧⠸⣿⣦⣥⣿⡇⡿⣰",
			"⢰⣿⡏⣴⣌⠈⣌⠡⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣬⣉⣉⣁⣄⢖⢕",
			"⢻⣿⡇⢙⠁⠴⢿⡟⣡⡆⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣵",
			"⣄⣻⣿⣌⠘⢿⣷⣥⣿⠇⣿⣿⣿⣿⣿⣿⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿",
			"⢄⠻⣿⣟⠿⠦⠍⠉⣡⣾⣿⣿⣿⣿⣿⣿⢸⣿⣦⠙⣿⣿⣿⣿⣿⣿⣿",
			"⡑⣑⣈⣻⢗⢟⢞⢝⣻⣿⣿⣿⣿⣿⣿⣿⠸⣿⠿⠃⣿⣿⣿⣿⣿⣿⡿",
			"⡵⡈⢟⢕⢕⢕⢕⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣿⣿⣿⣿⣿⠿⠋⣀",
			"⣿⣿⣿⢻⣿⣿⣿⣿⠻⣿⣿⡿⠿⠿⠿⣿⠻⡿⠻⠿⣿⡟⠛⠛⢛⣿⣿",
			"⣿⠏⣼⢸⡄⢿⢋⢸⣷⣇⢻⣿⣿⣿⣿⣿⡗⣥⠂⢦⣿⣭⢩⡍⣭⣽⣿",
			"⣿⣾⣛⣸⣿⣾⣾⣈⣛⣠⣿⣤⣤⣤⣤⣼⣴⣫⣶⣌⣻⣋⣼⣇⣋⣼⣿",
			"*/",
			"#include<bits/stdc++.h>",
			"",
			"using namespace std;",
			"",
			"#define ll long long",
			"#define endl '\\n'",
			"#define pr pair<int, int>",
			"#define MOD 0x7fffffff",
			"#define INF 0x7fffffff",
			"#define N 1000005",
			"",
			"inline int read() ",
			"{",
			"    int x = 0, neg = 1; char op = getchar();",
			"    while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar();}",
			"    while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar();}",
			"    return neg * x;",
			"}",
			"",
			"int main()",
			"{",
			"    $0",
			"    return 0;",
			"}"
		],
		"description": "start_cpp"
	},

邻接表建带权边:

"create_node_e":{
		"prefix": "crnde",
		"body": [
			"int idx = 0;",
			"",
			"int head[1000005], ne[1000005];",
			"",
			"struct node",
			"{",
    		"\tint u, v, w;",
    		"\tvoid init(int u, int v, int w)",
    		"\t{",
        	"\t\tthis->u = u;",
        	"\t\tthis->v = v;",
        	"\t\tthis->w = w;",
    		"\t}",
    		"\tbool operator == (node t) const",
    		"\t{",
        	"\t\treturn u == t.u && v == t.v && w == t.w;",
    		"\t}",
    		"\tbool operator < (node t) const",
    		"\t{",
        	"\t\treturn w < t.w;",
    		"\t}",
			"} e[1000005];",
			"",
			"void add_edge(int u, int v, int w)",
			"{",
    		"\te[++idx].init(u, v, w), ne[idx] = head[u], head[u] = idx;",
			"}",
		],
		"description": "建邻接表(有边)"
	},

邻接表建图(无权边):

"create_node_ne":{
		"prefix": "crndne",
		"body": [
			"int idx = 0;",
			"",
			"int head[1000005], ne[1000005];",
			"",
			"struct node",
			"{",
    		"\tint u, v;",
    		"\tvoid init(int u, int v)",
    		"\t{",
        	"\t\tthis->u = u;",
        	"\t\tthis->v = v;",
    		"\t}",
    		"\tbool operator == (node t) const",
    		"\t{",
        	"\t\treturn u == t.u && v == t.v;",
    		"\t}",
			"} e[1000005];",
			"",
			"void add_edge(int u, int v)",
			"{",
    		"\te[++idx].init(u, v), ne[idx] = head[u], head[u] = idx;",
			"}",
		],
		"description": "建邻接表(无边)"
	},

龟速乘:

"quick_multi": {
		"prefix": "qckmul",
		"body": [
			"ll quick_multi(ll a, ll b)",
			"{",
			"    ll sum = 0;",
			"    while (b)",
			"    {",
			"        if (b & 1) sum+= a, sum%= MOD;",
			"        a<<= 1, a%= MOD;",
			"        b>>= 1;",
			"    }",
			"    return sum;",
			"}"
		],
		"description": "龟速乘"
	},

快速幂:

"quick_pow": {
		"prefix": "qckpow",
		"body": [
			"ll quick_pow(ll x, ll y)",
			"{",
			"    ll sum = 1;",
			"    while (y)",
			"    {",
			"        if (y & 1) sum*= x, sum%= MOD;",
			"        x*= x, x%= MOD;",
			"        y>>= 1;",
			"    }",
			"    return sum;",
			"}"
		],
		"description": "快速幂"
	},

tarjan 缩点:

"tarjan 缩点": {
		"prefix": "tarshort",
		"body": [
			"int dfn[1000005], low[1000005];",
			"",
			"int ins[1000005], vis[1000005];",
			"",
			"int step = 0, cnt = 0;",
			"",
			"stack<int> stk;",
			"",
			"void tarjan(int x)",
			"{",
			"    dfn[x] = low[x] = ++step;",
			"    stk.push(x), ins[x] = 1;",
			"    for (int i = head[x]; i != -1; i = ne[i])",
			"    {",
			"        int u = e[i].u, v = e[i].v;",
			"        if (!dfn[v])",
			"        {",
			"            tarjan(v);",
			"            low[u] = min(low[u], low[v]);",
			"        }",
			"        else if (ins[v])",
			"        {",
			"            low[u] = min(low[u], dfn[v]);",
			"        }",
			"    }",
			"    if (dfn[x] == low[x])",
			"    {",
			"        ++cnt;",
			"        int v;",
			"        do",
			"        {",
			"            v = stk.top(), stk.pop(), ins[v] = 0;",
			"            vis[v] = cnt;",
			"        } while (x != v);",
			"    }",
			"}"
		],
		"description": "tarjan 缩点"
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值