zoukankan      html  css  js  c++  java
  • ZOJ 3498 Javabeans

    脑筋急转弯。

    如果是偶数个,那么第一步可以是$n/2+1$位置开始到$n$都减去$n/2$,后半段就和前半段一样了。

    如果是奇数个,那么第一步可以是$(n+1)/2$位置开始到$n$都减去$(n+1)/2$,$(n+1)/2$位置变成了$0$,之后的就和前半段一样了。

    递归下去即可。因此,答案就是$ans(n/2)+1$。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<ctime>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-10;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c))
        {
            x = x * 10 + c - '0';
            c = getchar();
        }
    }
    
    int T;
    int n;
    
    int get(int x)
    {
        if(x==1) return 1;
        return get(x/2)+1;
    }
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            printf("%d
    ",get(n));
        }
    
        return 0;
    }
  • 相关阅读:
    OC面向对象—封装
    OC面向对象—继承
    hdu 4612 Warm up(缩点+树上最长链)
    hdu 4604 Deque(最长不下降子序列)
    hdu 4607 Park Visit(树上最长链)
    hdu 4609 3-idiots(快速傅里叶FFT)
    codeforces 333B
    codeforces 333A
    codeforces 334B
    codeforces 334A
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6384496.html
Copyright © 2011-2022 走看看