閱讀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引發的排序不對問題