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. There is no 'root'@'%' registered解决

      把别人机器上的MYSQL中的一个数据库导出来,生成了一个.sql的文件   在我的机器上导入这个.sql文件之后,在数据库连接时出现了如下错误:   “There is no 'root'@'%' ...

  2. Windows server 2012R清除并重建SID 用于制作封装模板

    首先介绍下什么是SID SID也就是安全标识符(Security Identifiers),是标识用户.组和计算机帐户的唯一的号码.在第一次创建该帐户时,将给网络上的每一个帐户发布一个唯一的 SID. ...

  3. 洛谷P1494 [国家集训队]小Z的袜子

    Code: #include<cstdio> #include<iostream> #include<algorithm> #include<cstring& ...

  4. Hadoop2.x 关于日志文件位置

    查看日志是发现Hadoop问题和解决Hadoop问题的第一步. 开始我不知道该去哪找日志,后来我发现在我启动节点的时候,有打印信息以及明确告诉了日志写在哪. [root@master hadoop]# ...

  5. HTML提交表单

    一.使用form提交表单 <form action="#" method="post"> {% csrf_token %} 班级<input ...

  6. [Debug]SpaceVim中neomake报错 Error while trying to load a compilation database

    回家装上archlinux,突发奇想装个SpaceVim写题 安装配置一路可以说是没有太大问题 最后在写题时出现如下问题 Error while trying to load a compilatio ...

  7. 关于__str__的介绍

    在python语言里,__str__一般是格式是这样的. class A: def __str__(self): return "this is in str" 事实上,__str ...

  8. Python学习————列表的增删改查

    增加:li.append(对象):追加 注:print(li.append())--->是Noneli.insert(索引,对象):插入到相应位置li.extend(对象):可迭代的添加到尾部, ...

  9. POJ 题目3321 Apple Tree(线段树)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21566   Accepted: 6548 Descr ...

  10. 最快的方式清除Chrome浏览器DNS缓存

    最快的方式就是直接数据url,然后清除不须要的dns缓存. chrome://net-internals/#dns 一般步骤.要经过下列几项. Chrome - > 扳手 - > 选项 - ...