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 |
没道理阿。方法一样,怎么就TLE了?谁来告诉我啊!!In Reply To:我用了字符串的方法,有更高效的方法吗?? Posted by:church at 2007-05-20 11:28:50 这个是上面仁兄的 #include <iostream.h> #include <stdlib.h> #include <string.h> void main() { long i,j,k,m,n,sum; char a[10]; int radix=10; cin>>m; for(i=0;i<m;i++) { cin>>n; k=1; sum=1; while (n>sum) { n=n-sum; k++; ltoa(k,a,radix); sum=sum+strlen(a); } j=1; sum=1; ltoa(j,a,radix); while (n>sum) { n=n-sum; j++; ltoa(j,a,radix); sum=strlen(a); } n--; cout<<a[n]<<endl; } } 这个TLE #include<iostream> #include<cstring> using namespace std; int main() { //freopen("in.txt","r",stdin); int t; cin>>t; while(t--) { int n; char str[100]; cin>>n; int sum=0,s=0,i=1; while(n>sum) { itoa(i,str,10); s+=strlen(str); i++; sum+=s; } sum-=s; n-=sum; sum=0,i=1; while(n>sum) { itoa(i,str,10); sum+=strlen(str); i++; } i--; itoa(i,str,10); sum-=strlen(str); n-=sum; itoa(i,str,10); cout<<str[n-1]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator