您的位置:首页 > 其它

hdu 1032 水题也wrong 两次(于是乎更有刷水题的必要了)

2013-04-04 13:08 288 查看
题意:

清楚明了。

注意:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: