http://acm.hdu.edu.cn/showproblem.php?

pid=1032

这题能够用暴力求解。求出在[ni,nj]之间全部数字产生的最大值。

通过观察能够知道,当nk靠近nj的时候,产生的值越多,于是,我认为能够在暴力的基础上做一些小的变化。降低对ni,nj中值得考查

#include <stdio.h>
int main()
{
int m,n,i,max,count,t,j;
while(scanf ("%d %d",&m,&n)!=EOF)
{
if (m<n)
{
t=m;
m=n;
n=t;
}
max=1;
for (i=n;i<=m;i++)
{
count=1;
j=i;
while (j!=1)
{ if (j%2!=0)
{
j=j*3+1;
++count; }
else
{
j=j/2;
++count;
} if (max<count)
max=count; }
} printf ("%d %d %d\n",n,m,max);
}
return 0;
}

通过这段代码測试数据,发现基本上能对的上。。。。。可是HDOJ上面是Wrong Anwser。临时还没发现究竟是什么问题。。

希望看到这篇博客的各路大神能给个解答

#include<stdio.h>
int Length(int n)
{
int k=0;
while(n!=1)
{
if(n%2==1)
n=3*n+1;
else
n/=2;
k++;
}
return (k+1);
}
int main( )
{
int i,j,temp,max,t,small,large;
while(scanf("%d",&i)!=EOF)
{
scanf("%d",&j);
if(i<=j)
{
small=i;large=j;
}
else {
small=j;large=i;
}
temp=small;
max=Length(temp);
while(temp<=large)
{
t=Length(temp);
if(t>max)
max=t;
temp++;
}
printf("%d %d %d\n",i,j,max);
}
return 0;
}

这里附上别人AC的代码,我认为跟我写的也差点儿相同。

。。。。

/*******************************************/

简短挖坑,由于在网上看到了其它的费暴力解法。

[问题]HDOJ1032 The 3n + 1 problem的更多相关文章

  1. UVa 100 - The 3n + 1 problem(函数循环长度)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  2. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem A: The 3n + 1 problem(水题)

    Problem A: The 3n + 1 problem Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 6[Submit][St ...

  3. The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏

    The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53927   Accepted: 17 ...

  4. uva----(100)The 3n + 1 problem

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  5. 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)

    // The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...

  6. 100-The 3n + 1 problem

    本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...

  7. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  8. UVA 100 - The 3n+1 problem (3n+1 问题)

    100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...

  9. classnull100 - The 3n + 1 problem

    新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正  The 3n + 1 problem  Background Problems in Computer Science are o ...

随机推荐

  1. js函数参数理解

    eg: function setName(obj){ obj.name = "Nicholas"; obj = new Object(); obj.name = "Gre ...

  2. BZOJ2161: 布娃娃 整体二分

    Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...

  3. linux 安装常用库

    在CentOS安装软件的时候,可能缺少一部分支持库,而报错.这里首先安装系统常用的支持库.那么在安装的时候就会减少很多的错误的出现. [root@bogon 桌面]#  yum install -y ...

  4. grep的使用【转】

    grep的作用是显示匹配一个或多个模式的文本行.时常会作为管道(|)的第一步,以便对匹配的数据作进一步处理.grep常用于查找和替换文本的.在传统上,grep有3个版本:grep.egrep(扩展gr ...

  5. 不安全的直接对象引用:你的 ASP.NET 应用数据是否安全?

    介绍 作为一个在X94的航空工程师,你的老板要求你从2号楼的工程图中检索出一个特定的专利.不幸的是,进入大楼需要你出示你具有进入大楼的资格的证明,然后你迅速地以徽章的形式出示给了保安.到了十三楼,进入 ...

  6. 作为一名Android APP开发者的自我总结

    每当接近年尾,最痛苦的工作无疑是写年终总结,写总结的同时不禁感叹这一年过得不容易阿.突然想起这一年也是自己开发Android APP的第一年,于是觉得应该给自己的APP来一个年终总结. 一.开发方面严 ...

  7. How to: Create Custom Configuration Sections Using ConfigurationSection

    https://msdn.microsoft.com/en-us/library/2tw134k3.aspx You can extend ASP.NET configuration settings ...

  8. nodejs是什么

    nodejs是什么 一种javascript的运行环境,能够使得javascript脱离浏览器运行. 阅读本帖需要先复习小学语文课文,华罗庚的<统筹方法>. 比如,想泡壶茶喝.当时的情况是 ...

  9. AngularJs轻松入门源码托管至Github

    Github是全球最大的代码托管平台,笔者玩Github有一段时间了,有很多开源项目的源码都托管在Github上,笔者在上面也发现了不少优秀的开源代码. 每次写完博文想在最后附上文章相关的代码,但是由 ...

  10. ListView优化-ViewHolder缓存

    安卓开发中ListView控件是一个使用频率相当的高级控件,通常用于展示一系列相似度极高的数据,当数据量极大或布局相当复杂时,ListView的性能优化就显得非常重要.所以在开发中不但功能上要满足,而 ...