UVa 371 - Ackermann Functions
来源:互联网 发布:中国第一美女程序员 编辑:程序博客网 时间:2024/05/16 05:45
题目:3n+1经典问题,求区间中最大运算次数。
分析:模拟。直接在区间中计算,取最值即可。
注意:1.区间的端点可能是反的;2.计算过程中用long long防止溢出。
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int X( long long n ){if ( n == 1LL ) return 3;int count = 0;while ( n > 1LL ) {if ( n&1 ) n = (n<<1LL)+n+1LL;else n >>= 1LL;count ++;}return count;}int main(){int L,H,V,S;while ( scanf("%d%d",&L,&H) && L+H ) {if ( L > H ) swap( L, H );V = L;for ( int i = L+1 ; i <= H ; ++ i )if ( X( V+0LL ) < X( i+0LL ) )V = i;printf("Between %d and %d, %d generates the ",L,H,V);printf("longest sequence of %d values.\n",X(V+0LL));}return 0;}
0 0
- UVa 371 - Ackermann Functions
- UVa 371 Ackermann Functions (water ver.)
- uva371 Ackermann Functions
- Ackermann function
- Ackermann数
- Ackermann函数
- Ackermann函数
- FOJ 1042 Ackermann Function
- FZU 1042 Ackermann Function
- 强大的ackermann函数
- bjfu1025 Ackermann函数
- [SICP][1.10]Ackermann函数
- functions
- functions
- Functions
- Functions
- Functions
- Functions
- Ngnix Virtul Host 和 rewrite rule 示例
- 09. 属性的Attribute
- html之<marquee>详解
- JQuery的KinSlideshow插件打造超炫焦点轮播图,带参数说明
- Spring AOP Maven依赖,拦截加注解的方法参数
- UVa 371 - Ackermann Functions
- Ubuntu 12.04下安装Oracle Express 11gR2
- Linux 下配置Tinyxml,将其编译为静态库
- 修改wheelView,全部代码
- ubuntu中如何获取root权限
- What is TCP/IP?
- [Oracle命令] 基本表空间管理
- 深度对比Oracle与SQL Server – 第一部分
- C, C++, Java各自优势及应用领域