你还在为思路正确却TLE而烦恼吗?算法
我也没办法,谁让你是一枚蒟蒻呢函数
今天,本人给被TLE折磨的死去活来的各位介绍一个专治TLE的法宝:优化
输入优化函数:code
int Read() { int 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*10+ch-'0';ch=getchar();} //也能够改为这样:x=(x<<3)+(x<<1)+(ch^48),位运算更快一些 return x*f; }//使用方法:x=Read();
输出优化函数:blog
void Write(int n) { if(n<0) {putchar('-');n=-n;} if(n>9) Write(n/10); putchar(n%10+'0'); return; }//使用方法:Write(x);
注意!使用getchar()和putchar()要加头文件cstdioget
什么?你问我若是仍是TLE怎么办?it
老老实实回去改算法吧......io