跳转至

算法竞赛

约 84 个字 39 行代码 预计阅读时间 1 分钟

概要

说明

大一上学习算法竞赛的笔记.因为最近要准备校赛和蓝桥杯(不过大概率是重在参与),翻出来复习顺便写一下笔记.

常用模板

// 常用头文件
#include <iostream>
#include <algorithm>
#include <cstring>

// 万能头
#include <bits/stdc++.h>

// 取消同步流
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

// 简写
using ll = long long;
using PII = pair<int, int>;

// 链式前向星(不带权)
int h[N], e[M], ne[M], idx = 1;

void add(int a, int b)
{
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx++;
}

// 链式前向星(带权)
int h[N], e[M], ne[M], w[M], idx = 1;

void add(int a, int b, int c)
{
    e[idx] = b;
    w[idx] = c;
    ne[idx] = h[a];
    h[a] = idx++;
}

// 排序去重
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());