hdu 1032--3n+1
来源:互联网 发布:手机如何联系淘宝小二 编辑:程序博客网 时间:2024/05/01 04:40
/** \brief hdu 1032 -- the 3n+1 problem * * \param date 2014/7/20 * \param state AC * \return * */#include <iostream>#include <fstream>#include <cstdio>using namespace std;int ThreeNPlusOne(int n){ int sum=1; while(n!=1) { if(n%2) n=3*n+1; else n=n/2; sum++; } return sum;}int main(){ //cout << "Hello world!" << endl; //freopen("input.txt","r",stdin); int a,b; while(scanf("%d%d",&a,&b)!=EOF) { cout<<a<<" "<<b<<" "; int M,S=0; int t; if(a>b)//大小不确定 { t = a; a = b; b = t; } M=0; for(int i=a;i<=b;i++) { S=ThreeNPlusOne(i); if(S>M) M=S; /*int sum=1; int n=i; while(n-1) { if(n%2) n=3*n+1; else n=n/2; sum++; } if(sum>M) M=sum;*/ } //cout<<a<<" "<<b<<" "<<M<<endl; cout<<M<<endl; } return 0;}
0 0
- HDU 1032 3N+1
- hdu 1032--3n+1
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu-1032-The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- 杭电1102 Constructing Roads
- [C/C++标准库]_[初级]_[使用std::sort排序各种类型数据]
- 36 最长公共子序列
- Cocos2d-x中的文件读取操作
- Android中ListView的各种显示效果
- hdu 1032--3n+1
- 制作不暴露源码的Android Library Project
- 37 回文字符串
- 从 "specified with /SECTION option does not exist" 说开
- GNUstep 搭建Objective C编译环境教程
- linux 启动过程分析
- 39 水仙花数
- Info.plist详解
- 40 公约数和公倍数