Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请大家见证一下16MS和375MS的差距其中initialize(),exp3()函数完全一样. printf("%S",**)整串输出为什么比printf("%C",**)一个个输出快那么多呢? 375MS代码: int main() { int n,t,i; initialize(); while(scanf("%d",&n)!=EOF){ t=exp3(n); for(i=0;i<t;i++) printf("%c",fractal[i]); printf("\n"); } return 0; } 16MS代码: int main() { int n,t; initialize(); while(scanf("%d",&n)!=EOF){ t=exp3(n); fractal[t]='\0'; printf("%s\n",fractal); fractal[t]=' '; } return 0; } ======================大家好,我是所向披靡的分割线================= int rec[8195]; char fractal[531445]; int exp3(int e) { int s=1,i=0; while(i++<e) s*=3; return s; } void initialize() { int i,j,r,s,t; memset(fractal,'-',sizeof(fractal)); for(r=i=0;i<=11;i++){ t=exp3(i); rec[r++]=t; s=r-1; for(j=0;j<s;j++) rec[r++]=rec[j]; } for(s=i=0;i<r;i++){ for(j=0;j<rec[i];j++) fractal[++s]=' '; ++s; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator