Skip to content
算法指北

Created by open17Created by open17 2024

神秘口诀

审题仔细莫大意,看漏看错要不得

条件数据要关注,复杂度里藏算法

新题难解找相似,转化问题是妙计

手玩打表找规律,性质特点要牢记

思路卡住别着急,条件未用要想起

单调递增或递减,构造性质有奇迹

暴力枚举是起点,优化思路步步来

正向思考太困难,反向推理试试看

复杂问题先简化,循序渐进不慌张

贡献思想要记住,容斥或许有奇效

火车头
cpp
#ifndef TEMPLATE_H
#define TEMPLATE_H

#ifdef USE_LL
#define int long long
#endif

#ifdef USE_STD
using namespace std;
#endif

// 辅助宏
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define _rep(i, l, r) for (int i = (l); i >= (r); i--)
#define all(x) (x).begin(), x.end()
#define endl '\n' // 避免刷新缓冲区
#define inf32 0x3f3f3f3f
#define inf64 1LL << 60
#define max32 INT_MAX

#ifdef DEBUG
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for (auto x : a) cout << x << " "; cout << "\n";
#endif

#ifndef DEBUG
#define debug(x)
#define vdebug(a)
#endif

// 类型别名
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using pii = std::pair<int, int>;

// print
template <typename T>
void print(const T &t) { std::cout << t << endl; }
template <typename T, typename... Args>
void print(const T &t, const Args... args)
{
    std::cout << t << ' ';
    print(args...);
}

i64 ceilDiv(i64 n, i64 m)
{
    if (n >= 0)
    {
        return (n + m - 1) / m;
    }
    else
    {
        return n / m;
    }
}

i64 floorDiv(i64 n, i64 m)
{
    if (n >= 0)
    {
        return n / m;
    }
    else
    {
        return (n - m + 1) / m;
    }
}

template <class T>
void chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
    }
}

template <class T>
void chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
    }
}

template <class T>
T gcd(T a, T b)
{
    return b ? gcd(b, a % b) : a;
}

// 快读快写实现
inline i64 read()
{
    i64 x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * (i64)10 + (i64)(ch - '0');
        ch = getchar();
    }
    return x * f;
}

inline void write(int x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

void IO(void (*solve_func)())
{
    int TEM_T = 1;
#ifdef IN_FILE
    freopen(IN_FILE, "r", stdin);
#endif

#ifdef OUT_FILE
    freopen(OUT_FILE, "w", stdout);
#endif

#ifdef REAP_READ
    std::cin >> TEM_T;
#endif

#ifdef USE_IOS
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
#endif
    while (TEM_T--)
    {
        solve_func();
    }
}
#endif // TEMPLATE_H

更新日志

  • 2025-04-03 修订版

    • 重构全部内容
  • 2024-01-01 初始版本

    • 目前很多模板是东拼西凑网上+从我的上古代码/笔记啥的拿出来的
    • 有待统一化与完善