读优&&输优

很nb的技巧……
但奇怪的是只能对文件使用……

然而交到OJ上或者比赛的时候都没有关系→_→

我大概也只能弄弄这些花里胡哨的东西了→_→

原理不清楚,背个板子好了

读优

 1 #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
 2 char buf[1<<21],*p1=buf,*p2=buf;
 3 inline int read(){
 4     #define num ch-'0'
 5     char ch;bool flag=0;int res;
 6     while(!isdigit(ch=getc()))
 7     (ch=='-')&&(flag=true);
 8     for(res=num;isdigit(ch=getc());res=res*10+num);
 9     (flag)&&(res=-res);
10     #undef num
11     return res;
12 }

输优

1 char obuf[1<<24],*o=obuf;
2 void print(int x){
3     if(x>9) print(x/10);
4     *o++=x%10+48;
5 }

实际使用(要换行的话)

1 print(x);
2 *o++='\n';

然后在程序的最后加上一句

1 fwrite(obuf,o-obuf,1,stdout);

感觉我在不归路上越走越远了→_→

猜你喜欢

转载自www.cnblogs.com/bztMinamoto/p/9383545.html