一直觉得读入优化没什么,,但是,,,有的时候超时了用个读入优化竟然能过。。。。哭了。。。
用的时候,read(n) 就好。
读入优化要在大数据的时候用比较好。
template<class T> inline char read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' | c > '9') && c != '-' && c != EOF) c = getchar(); if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return c; } template <class T> inline void write(T n) { if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48); }
吓傻了。。。为什么有的时候用读入优化反而更慢了呢。。。。。。。