阅读754 返回首页    go 阿里云 go 技术社区[云栖]


11384 - Help is needed for Dexter 模拟 98

   分治法

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int org[10001];
int f(int now)
{
    if(now>10000)
        return f(now>>1)+1;
    if(org[now])return org[now];
    return org[now]=f(now>>1)+1;
}
int main()
{
    int n;
    memset(org,0,sizeof(org));
    org[1]=1;
    while(~scanf("%d",&n))
    {
        printf("%d\n",f(n));
    }
}


最后更新:2017-04-03 15:22:09

  上一篇:go Java面向对象高级--实例分析—宠物商店
  下一篇:go Core Data多线程环境下pendingChange引发的排序不对问题