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 |
哪位高手救救小妹!我现在也搞不清是什么问题?谢谢~~~~~~#include<stdio.h> #include<vector> #define number 5 using namespace std; /*int link(int k) { int n=1; while(k!=1){ if(k%2==1)k=3*k+1; else k=k/2; n++; } return n; } */ int link(int k) { vector<int>arry(1); int i=0,n=1,flag=0,len; while(k!=0) { arry[i++]=k%10; k=k/10; } while(!flag) { if(arry[0]!=1)flag=0; else {for(int j=1;j<arry.size();j++) { if(arry[j]!=0){ flag=0; break;} } if(j>=arry.size()) flag=1; } if(!flag) { if(arry.front()%2==0){ for(int t=arry.size()-1;t>=1;t--) { if(arry[t]<2){arry[t-1]+=(arry[t]*10);arry[t]=0;} else if(arry[t]%2==0) arry[t]=arry[t]/2; else { arry[t]=arry[t]/2; arry[t-1]+=((arry[t]%2)*10); } } if(t==0)arry[t]=arry[t]/2; n++; } else { for(int p=0;p<arry.size();p++) arry[p]*=3; arry[0]+=1; len=arry.size(); for(int q=0;q<len;q++) { arry[q+1]=arry[q]/10; arry[q]=arry[q]%10; } n++; } } } return n; } int nn(int i,int j) { int max=0; for(int k=i;k<=j;k++) { if(link(k)>=max)max=link(k); } return max; } void main() { int x[number][2]; for(int i=0;i<number;i++) {scanf("%d %d",&x[number][0],&x[number][1]); printf("%d %d %d\n",x[number][0],x[number][1],nn(x[number][0],x[number][1])); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator