hdu 1032 水题也wrong 两次(于是乎更有刷水题的必要了)
题意:
清楚明了。
注意:
1.For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j
并没有说i<j一定成立;
2.The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
i 和 j一定要输入的顺序与输出的顺序一样。
于是就可以RE了!!!
View Code
#include<stdio.h> int main() { int n,m; int sum; int max; int i; int t,k; while(scanf("%d %d",&n,&m)!=EOF) { max=1; k=0; if(n>m){k=1;t=m;m=n;n=t;} for(int j=n;j<=m;j++) { i=j; sum=1; while(i!=1) { sum++; if(i%2==0)i/=2; else i=i*3+1; } if(sum>max)max=sum; } if(k==0)printf("%d %d %d\n",n,m,max); else printf("%d %d %d\n",m,n,max); } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步