1207:The 3n + 1 problem
来源:互联网 发布:java中网络编程详解 编辑:程序博客网 时间:2024/06/11 06:27
题目链接:http://poj.org/problem?id=1207
方法:简单模拟
思路:好吧,我承认是因为今天HDUoj系统关闭了,只好试试poj了,这个题不难,水题,折腾那么长时间我也是醉了,按照题意简单模拟就可以了,但是要注意一点,给出数据的大小关系不定,是需要自己判定的,不知道题目哪里说明的,反正我是没看见,眼瞎。
难点:审题
#include <iostream>#include<climits>using namespace std;int findlen(int x){ int num = 0; while(x != 1) { if(x%2 == 0) x /= 2; else x = 3*x+1; num++; } return num+1;}int main(){ int a,b; while(cin>>a>>b) { cout<<a<<" "<<b<<" "; if(a>b) { int t; t = a; a = b; b = t; } int maxmum =INT_MIN ; for(int i = a;i <= b;i++) { if(findlen(i) > maxmum) maxmum = findlen(i); } cout<<maxmum<<endl; }}
0 0
- PKU 1207 The 3n + 1 problem
- pku 1207 The 3n + 1 problem
- poj 1207 The 3n + 1 problem
- POJ 1207 The 3n + 1 problem
- poj 1207 The 3n + 1 problem
- 1207 The 3n + 1 problem
- POJ 1207 The 3n + 1 problem
- PKU 1207 The 3n + 1 problem
- poj 1207 The 3n + 1 problem
- POJ 1207 - The 3n + 1 problem
- POJ 1207 The 3n + 1 problem
- POJ 1207 The 3n + 1 problem
- The 3n+1 problem POJ 1207
- POJ 1207 The 3n + 1 problem
- OpenJudge - 1207:The 3n + 1 problem
- POJ 1207: The 3n+1 problem
- The 3n + 1 problem(POJ--1207
- POJ-1207 The 3n + 1 problem
- 洛谷2583 地铁间谍
- 函数的可重入性理解
- jquery
- Ubuntu常用命令
- arm处理器编程模型
- 1207:The 3n + 1 problem
- linux下解压命令大全
- Error:<Error>: ImageIO: CGImageReadCreateDataWithMappedFile...error = 2 (No such file or directory)
- arrayToString方法 String StringBuffer比较
- 直方图均衡化
- 数据库异常:在对应所需名称或序数的集合中,未找到项目
- git操作流
- golang初体验
- pqxx 的基本使用