题目链接:https://cn.vjudge.net/problem/HDU-1032

水题

代码

#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX=8388608;
int num[MAX], a, b;
int solve(int n){
if (n<MAX && num[n]) return num[n];
if (n==1) return 1; if (n%2) return (n<MAX)?(num[n]=solve(3*n+1)+1):(solve(3*n+1)+1);
else return (n<MAX)?(num[n]=solve(n/2)+1):(solve(n/2)+1);
} int main(void){
while (scanf("%d%d", &a, &b)==2){
int ans=1;
for (int i=min(a, b); i<=max(a, b); i++) ans=max(ans, solve(i));
printf("%d %d %d\n", a, b, ans);
} return 0;
}

HDU-1032 The 3n+1 problem 模拟问题(水题)的更多相关文章

  1. 题解报告:hdu 1032 The 3n + 1 problem(克拉兹问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1032 Problem Description Problems in Computer Science ...

  2. HDU 1032 The 3n + 1 problem (这个题必须写博客)

    The 3n + 1 problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. HDU 1032.The 3n + 1 problem【注意细节】【预计数据不强】【8月21】

    The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belongin ...

  4. HDU 1032 The 3n + 1 problem

    还以为要递归推一推的 结果暴力就过了 要注意 i,j 大小 #include <iostream> using namespace std; int a,b; long long cnt, ...

  5. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  6. CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】

    CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...

  7. 杭电OJ——1032 The 3n + 1 problem

    The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belongin ...

  8. hdu 1012:u Calculate e(数学题,水题)

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. HDU 5889 Barricade(最短路+最小割水题)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

随机推荐

  1. 1.future线程通信

    #include <future> #include<iostream> #include <thread> #include <thread> #in ...

  2. C++ 获取某一文件夹下的所有文件名

    //********************************************************************** // Method: 获取文件夹下所有文件 // Fu ...

  3. SpringCloud学习笔记(7)----Spring Cloud Netflix之负载均衡-Ribbon的深入理解

    1. 注解@LoadBalanced 作用:识别应用名称,并进行负载均衡. 2. 入口类:LoadBalancerAutoConfiguration 说明:类头上的注解可以知道Ribbon 实现的负载 ...

  4. SpringBoot学习笔记(5)----SpringBoot中异常处理的三种方法

    对于异常的处理,Spring Boot中提供默认的一个异常处理界面,如下图: 但是在实际的运用开发中,这样的页面显然是不友好的,Spring Boot也提供了自定义异常处理的方式,如下总结三种一场处理 ...

  5. 获取鼠标经过处的标签的标签名和id

    <script> var el = window.document.body; // 声明一个变量,默认值为body window.document.body.onmouseover = ...

  6. data structure alignment(数据对齐)

    概述: 数据对齐指数据在计算机内存中排放和获取的方式.包含三个方面:数据对齐(data alignment).数据结构填充(data alignment).打包(packing) 如果数据是自然对齐的 ...

  7. Python 线程高级篇 threading 模块的使用

    创建一个tread实例,给他传一个函数 #!/usr/bin/python import threading from time import * loops =[4,2] def loop (nlo ...

  8. VUEJS开发规范

    VUEJS开发规范 基于组件化开发理解 组件命名规范 结构化规范 注释规范 编码规范 基于组件化开发理解 什么是组件? ``` 组件其实就是页面组成的一部分,好比是电脑中的每一个元件(如硬盘.键盘.鼠 ...

  9. Python格式化字符串、占位符、合并数组

    合并数组 参考链接:https://www.cnblogs.com/chaihy/p/7243143.html >>> a=[2] >>> b=[3] >&g ...

  10. Ask DevOps: Top 5 Business Alternatives to Splunk

    https://siliconangle.com/blog/2012/11/20/ask-devops-top-5-business-alternatives-to-splunk/