hdoj1032 3n+1问题 time limit exceeded #includeint main(void){int i=0,j=0,n=1,temp=0;while((scanf("%d %d",&i,&j))!=EOF){temp=j;n=1;while(temp!=i){if (temp%2==0) {temp=temp/2;n++;}else {temp=3*temp+1;n++;}}printf("%d %d %d\n",i,j,n);}}
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 18:59:08
hdoj1032 3n+1问题 time limit exceeded #includeint main(void){int i=0,j=0,n=1,temp=0;while((scanf("%d %d",&i,&j))!=EOF){temp=j;n=1;while(temp!=i){if (temp%2==0) {temp=temp/2;n++;}else {temp=3*temp+1;n++;}}printf("%d %d %d\n",i,j,n);}}
hdoj1032 3n+1问题 time limit exceeded
#include
int main(void){
int i=0,j=0,n=1,temp=0;
while((scanf("%d %d",&i,&j))!=EOF){
temp=j;
n=1;
while(temp!=i){
if (temp%2==0) {
temp=temp/2;
n++;
}
else {
temp=3*temp+1;
n++;
}
}
printf("%d %d %d\n",i,j,n);
}
}
hdoj1032 3n+1问题 time limit exceeded #includeint main(void){int i=0,j=0,n=1,temp=0;while((scanf("%d %d",&i,&j))!=EOF){temp=j;n=1;while(temp!=i){if (temp%2==0) {temp=temp/2;n++;}else {temp=3*temp+1;n++;}}printf("%d %d %d\n",i,j,n);}}
说明你的程序效率太低,超时了!