更简单的水题,穷举法即可。

需要注意的点:

1.i 和 j的大小关系不确定,即有可能 i>j

2.即使i>j,最后输出的结果也要严格按照输出,亦即如果输入10,1,则对应输出也应为 10 1 20而不是1 10 20

代码如下:

 /*
* File: 1207.h
* Author: chrischeng021 <chrischeng021@gmail.com>
*
* Created on July 9, 2015, 5:07 PM
*/ #ifndef _1207_H
#define _1207_H int calculate(int n){
int count = ;
while(n != ){
n = (n% == ? n/ : *n+);
count++;
}
return count;
} void process(){
int i,j,k,ret,tmp,left,right;
while(scanf("%d%d",&i, &j) != EOF && i > ){
ret = ;
if(i < j){
left = i;
right = j;
}
else{
left = j;
right = i;
}
for(k = left;k <= right;k++){
tmp = calculate(k);
ret = ret > tmp ? ret : tmp;
}
printf("%d %d %d\n",i, j, ret);
}
}
#endif
/* _1207_H */

POJ 1207 3N+1 Problem的更多相关文章

  1. 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 ...

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

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

  3. 烟大 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 ...

  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. 转Fiddler 构造http请求

    今天使用Fiddler构造一个POST请求,server端的PHP脚本的 $_POST数组中怎么也获取不到值,后来偶然发现是因为缺少了一个http头:Content-Type: application ...

  2. cas错误:org.jasig.cas.client.validation.TicketValidationException: No principal was found in the response from the CAS server.

    这个问题困扰了我好几天,最终被这个哥们解决了,具体请参考:http://www.oschina.net/question/252484_149958?sort=time

  3. 关于v-model、v-for、v-on的用法

    展示Holle Vue     window.onload = function(){         var box = new Vue({             el:'#div',      ...

  4. 在Mvc中进行异步请求是出现(没有为该对象定义无参数的构造函数)

    解决办法就是给相应的类添加无参数的构造函数:

  5. Debian 8 下安装持续集成的工具Jenkins

    前情提示:Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. 第一种方法: 1.1 配置java环境变量    解压java到相应目录,我一般习惯把安装的软件 ...

  6. 罪恶的SEO优化

    1. 基础概念开始 SEO,搜索引擎优化.概括来说就是针对分析搜索引擎的网站收录以及评价规律,来对网站的结构,内容以及其他因素作出一些合理调整,使得网站更容易被搜索引擎收录,并且能够尽量排在搜索引擎自 ...

  7. Python输入一个数字打印等腰三角形

    要求 用户输入一个数字,按照数字打印出等腰三角形 思路 1,用户输入的数字为n代表一共有多少行 2,使用一个循环带两个for循环,第一层循环是循环行数,第二层两个平行for循环一个打印空格一个打印*号 ...

  8. MFC基础程序设计VS2015 最新03

    视频教程地址观看:http://pan.baidu.com/s/1mhKQ6kK 一.数字(浮点数或整数)转为文字:a)如果转为窄字符字符串,sprintf函数很好用,浮点数都没问题:b)如果转为宽字 ...

  9. MySQL · 引擎特性 · InnoDB Buffer Pool

    前言 用户对数据库的最基本要求就是能高效的读取和存储数据,但是读写数据都涉及到与低速的设备交互,为了弥补两者之间的速度差异,所有数据库都有缓存池,用来管理相应的数据页,提高数据库的效率,当然也因为引入 ...

  10. spring boot入门(一)自己动手搭建spring boot

    spring boot官方文档  http://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/index.html 此篇文章 ...