X-man

导航

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;
}
复制代码

 

posted on   雨钝风轻  阅读(144)  评论(0编辑  收藏  举报

努力加载评论中...
点击右上角即可分享
微信分享提示