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. schema文件及XML文件的DOM和Sax解析

    schema文件 <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="htt ...

  2. U盘安装CentOS 7系统

    首先,本文适合新的不能再新的新手 小白出身的轩轩,由于最近正在学习Linux的centos系统,所以突发奇想,为什么不把轩轩的本机也安装一个centos系统呢,让两个系统互不干扰,想到就做到,遂开始动 ...

  3. Mysql学习总结(22)——Mysql数据库中制作千万级测试表

    前言: 为了方便测试性能.分表等工作,就需要先建立一张比较大的数据表.我这里准备先建一张千万记录用户表. 步骤: 1 创建数据表(MYISAM方式存储插入速度比innodb方式快很多) 数据表描述 数 ...

  4. CentOS6.3从光盘安装gcc(更改yum源)[转]

    转自:http://www.linuxidc.com/Linux/2012-11/73826.htm 一.加载光盘镜像 加载本地bin-DVD镜像文件到虚拟机系统,如图所示: 二.更改yum源 1.挂 ...

  5. cogs 141. [USACO Jan08] 奶牛的选举

    141. [USACO Jan08] 奶牛的选举 ★   输入文件:elect.in   输出文件:elect.out   简单对比时间限制:1 s   内存限制:16 MB 在推翻了Farmer J ...

  6. 9种常见的Android开发错误及解决方案

    整理总结了9个Android开发中的错误以及解决方案,共同探讨进步! 1. 如果你的项目的R文件不见的话,可以试下改版本号在保存,R文件不见一般都是布局文本出错导致. 2. 布局文件不可以有大写字母 ...

  7. Python: PS 滤镜--碎片特效

    本文用 Python 实现 PS 滤镜中的碎片特效,这个特效简单来说就是将图像在 上,下,左,右 四个方向做平移,然后将四个方向的平移的图像叠加起来做平均.具体的效果图可以参考之前的博客 http:/ ...

  8. Spring Boot: Tuning your Undertow application for throughput--转

    原文地址:https://jmnarloch.wordpress.com/2016/04/26/spring-boot-tuning-your-undertow-application-for-thr ...

  9. 搭建Hadoop的全分布模式

    此教程仅供参考 注意:此文档目的是为了本人方便以后复习,不适合当教程,以免误导萌新... 1.安装三台Linux2.在每台机器上安装JDK3.配置每台机器的免密码登录 (*) 生成每台机器的公钥和私钥 ...

  10. MVC中几种常用的ActionResult

    一.定义 MVC中ActionResult是Action的返回结果.ActionResult 有多个派生类,每个子类功能均不同,并不是所有的子类都需要返回视图View,有些直接返回流,有些返回字符串等 ...