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 |
Re:AC代码和TLE代码,求助In Reply To:AC代码和TLE代码,求助 Posted by:sdau_085111 at 2011-01-14 22:59:32 > 不知道为什么TLE,时间复杂度高?还是逻辑有问题?!高手帮忙 > AC代码 > /* Author : yan > * Question : POJ 2509 Peter's smokes > * Data && Time : Friday, January 14 2011 10:21 PM > * Compiler : gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 > */ > #include<stdio.h> > > int main() > { > freopen("input","r",stdin); > int n,k; > int ans; > while(scanf("%d %d",&n,&k)!=EOF) > { > ans=n; > > while(n>=k) > { > ans+=n/k; > n=n/k+n%k; > } > > printf("%d\n",ans); > } > return 0; > } > > TLE代码 > /* Author : yan > * Question : POJ 2509 Peter's smokes > * Data && Time : Friday, January 14 2011 10:21 PM > * Compiler : gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 > */ > #include<stdio.h> > > int main() > { > freopen("input","r",stdin); > int n,k; > int ans; > while(scanf("%d %d",&n,&k)!=EOF) > { > ans=n; > > while(n>=k) > { > n-=k; > ans++; > n++; > } > printf("%d\n",ans); > } > return 0; > } 应该是时间复杂度高 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator