|
|
back to boardwhy? Posted by aaa 28 Feb 2009 17:40 where i am wrong please write me aramvmv@mail.ru #include <iostream> using namespace std; __int64 i,n,k, o[20110]={0},l=0, s,t,j,m,r; char a[20110], c[20110]; int main() { cin.ignore(); cin.getline(a,20110); n=strlen(a); k=n; t=1; while(k!=0) {c[(k+1)/2]=a[t]; o[(k+1)/2]=1; k=(k+1)/2; t++; } for(j=0;j<n/4;j++) { for(i=1;i<=n;i++) if(o[i]==0) {l=1; m=s=i; while(o[i+l]==0) {l++; m+=i+l;} if(l==0) break; if(l==1) {c[s]=a[t]; o[s]=1;} else {k=m/l; while(k>=s) {c[k]=a[t]; o[(k+1)/2]=1; l/=2;m=0; for(r=s;r<s+l;r++)m+=r; k=m/l; t++; }}}} for(i=1;i<=n;i++) cout<<c[i]; return 0;} Re: why? Posted by riVers 7 Mar 2009 12:49 time limit? Re: why? Posted by aaa 8 Mar 2009 15:24 no crash Re: why? Posted by aaa 8 Mar 2009 15:27 here is my new solution but again crash #include <iostream> using namespace std; __int64 i,n,k, o[20110]={0},l=0, s,t,j,m,r; char a[20110], c[20110]; int main() { cin.ignore(); cin.getline(a,20110); n=strlen(a); k=n; t=1; while(k!=0) {c[(k+1)/2]=a[t]; o[(k+1)/2]=1; k=(k+1)/2; t++; } for(j=0;j<n/4;j++) { for(i=1;i<=n;i++) if(o[i]==0) {l=1; s=i; while(o[i+l]==0) {l++; } if(l==0) break; if(l==1) {c[s]=a[t]; o[s]=1;} else {k=s+l; while(k>=s) {c[(k+s)/2]=a[t]; o[(k+s)/2]=1; k=(k+s)/2; t++; }}l=0; }} for(i=1;i<=n;i++) cout<<c[i]; return 0;} Re: why? I solved this problem by Java with recursive function. I think it's more easy :) Re: why? Posted by edya 23 Aug 2011 15:06 recursive function is the best method for solving this problem, i thenk =D |
|
|