POJ 1207 3N+1 Problem
更简单的水题,穷举法即可。
需要注意的点:
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的更多相关文章
- 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 ...
- UVa 100 - The 3n + 1 problem(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 烟大 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 ...
- uva----(100)The 3n + 1 problem
The 3n + 1 problem Background Problems in Computer Science are often classified as belonging to a ...
- 【转】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 / ...
- 100-The 3n + 1 problem
本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
- 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 ...
- UVA 100 - The 3n+1 problem (3n+1 问题)
100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...
- classnull100 - The 3n + 1 problem
新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正 The 3n + 1 problem Background Problems in Computer Science are o ...
随机推荐
- 微信公众号开发笔记2(nodejs)
本篇主要记录调用微信各种api和功能实现 一.始于access_token 无论调用微信的什么api,都需要一个查询参数,就是我们每隔1小时或者2小时获取的access_token,笔记1中已经保证了 ...
- Lazyman功能实现
题目要求是这样的: 实现一个LazyMan,可以按照以下方式调用: LazyMan("Hank")输出: Hi! This is Hank! LazyMan("Hank& ...
- [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...
- Spring IOC的使用
控制反转就是应用本身不负责依赖对象的创建及维护,依赖对象的创建及维护是由外部容器负责的.这样控制权就由应用转移到了外部容器,控制权的转移就是所谓反转,目的是为了获得更好的扩展性和良好的可维护性.所谓依 ...
- ThreadGroup详解
①定义线程组 ThreadGroup类中有 2个构造方法,它们用来定义线程组.这 2个构造方法的使用格 式如下: public ThreadGroup(String name); public Th ...
- String的Intern方法详解
引言 在 JAVA 语言中有8中基本类型和一种比较特殊的类型String.这些类型为了使他们在运行过程中速度更快,更节省内存,都提供了一种常量池的概念.常量池就类似一个JAVA系统级别提供的缓存.8种 ...
- 一步步学习EF Core(1.DBFirst)
前言 很久没写博客了,因为真的很忙,终于空下来,打算学习一下EF Core顺便写个系列, 今天我们就来看看第一篇DBFirst. 本文环境:VS2017 Win7 .NET Core1.1 ...
- React入门---开始前的准备(下)-3
React开始前的准备(下): ·配置webpack热加载(热加载就是修改js文件,点击保存之后,浏览器会自动刷新,提高开发效率) 1. 全局安装: npm install webpack -g np ...
- 【JAVAWEB学习笔记】21_多条件查询、attr和prop的区别和分页的实现
今天主要学习了数据库的多条件查询.attr和prop的区别和分页的实现 一.实现多条件查询 public List<Product> findProductListByCondition( ...
- Servlet路径映射
Serlvlet路径映射 当一个请求发送到servlet容器的时候,容器先会将请求的url减去当前应用上下文的路径作为servlet的映射url. 容器默认请求的是一个Servlet,所以不会直接根据 ...