zoukankan      html  css  js  c++  java
  • UOJ66 新年的巧克力棒

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

    本文作者:ljh2000 
    作者博客:http://www.cnblogs.com/ljh2000-jump/
    转载请注明出处,侵权必究,保留最终解释权!

    题目链接:http://uoj.ac/problem/66

    正解:结论+数学归纳法证明

    解题报告:

      看到这题第一想法就是猜一波结论,开始猜每次/2,然而过不了样例。

      想了一想,似乎每次找到<=n的2^t,显然2^t贡献就是2^t-1,再把剩下的部分递归算就好了。结果就这么AC辣...

      UOJ上vfleaking用数学归纳法给出了证明:http://vfleaking.blog.uoj.ac/blog/100

    //It is made by ljh2000
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <complex>
    using namespace std;
    typedef long long LL;
    int n,ans;
    
    inline int getint(){
        int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
        if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
    }
    
    inline void dfs(int m){
    	if(m<=1) return ;
    	int t=1; for(;t<=m;t<<=1) ; t>>=1;
    	ans+=t-1;
    	dfs(m-t);
    }
    
    inline void work(){
    	int T=getint();
    	while(T--) {
    		n=getint(); ans=0;
    		dfs(n);
    		printf("%d
    ",ans);
    	}
    }
    
    int main()
    {
        work();
        return 0;
    }
    

      

  • 相关阅读:
    jmeter正则表达式书写
    Jmeter中if控制器的使用
    Jmeter组件之-Test Fragment(测试片段)
    Jmeter生成测试报告
    idea+maven+testng环境搭建以及基本使用
    ArrayList,HashSet,HashMap
    JAVA提供了八大基本数据类型对应的引用数据类型
    Properties解析
    JSON解析
    excel 解析
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6351257.html
Copyright © 2011-2022 走看看