技巧合集

输入输出

关闭同步流

cin、cout的速度在没有关闭同步流时特别慢~~,但是如果写这一行:

ios::sync_with_stdio(false);

那么上述结论不一定成立(scanf、 printf动态确定数据类型)

自我实现快读快写

因为getchar()、putchar()更快,所以:

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

后记:此blog日后将继续更新。

posted @ 2022-06-29 13:07  Mollin  阅读(26)  评论(0)    收藏  举报