c++输入挂

作者: qwq 分类: 算法 发布时间: 2018-02-21 21:19

普通版:

ios::sync_with_stdio(0);

加强版

inline void scan_d(T &ret)
{
    char c;
    ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}

终极版:

#define FI(n) FastIO::read(n)  
  
namespace FastIO {  
    const int SIZE = 1 << 16;  
    char buf[SIZE], obuf[SIZE], str[60];  
    int bi = SIZE, bn = SIZE, opt;  
    int read(char *s) {  
        while (bn) {  
            for (; bi < bn && buf[bi] <= ' '; bi++);  
            if (bi < bn) break;  
            bn = fread(buf, 1, SIZE, stdin);  
            bi = 0;  
        }  
        int sn = 0;  
        while (bn) {  
            for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];  
            if (bi < bn) break;  
            bn = fread(buf, 1, SIZE, stdin);  
            bi = 0;  
        }  
        s[sn] = 0;  
        return sn;  
    }  
    bool read(int& x) {  
        int n = read(str), bf;  
  
        if (!n) return 0;  
        int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;  
        for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';  
        if (bf < 0) x = -x;  
        return 1;  
    }  
};  

 

POJ 2492为例:

普通版:

StatusAccepted
Time4297ms
Memory752kB

加强版:

StatusAccepted
Time125ms
Memory732kB

终极版:

StatusAccepted
Time110ms
Memory756kB

发表评论

电子邮件地址不会被公开。 必填项已用*标注