Hdu 4588 Count The Carries (规律)
来源:互联网 发布:广西老年大学网络报名 编辑:程序博客网 时间:2024/06/06 09:29
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4588
思路:
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
观察可知,第i位有(1<<i)个0,与(1<<i)个1,按照长度为(1<<(i+1))长度循环。则对于数n,可以求出1到n中各位1的个数num2[i],则进位次数为sum(num[i] / 2),注意每次向高位进位(num2[i+1]+=num2[i] / 2)。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;LL num1[65],num2[65];void solve(LL num[],LL n){ for(int i=0;i<63;i++) num[i]=0; n++; for(int i=0;i<63;i++) { LL tmp1=(1LL)<<(i+1); LL tmp2=(1LL)<<i; num[i]+=n/tmp1*(1<<i); if(n%tmp1>tmp2)num[i]+=n%tmp1-tmp2; } /*for(int i=0;i<63;i++) cout<<i<<" "<<num[i]<<endl;*/}int main(){ LL a,b; //solve(num1,20); //solve(num2,6); while(scanf("%I64d%I64d",&a,&b)==2) { solve(num1,a-1); solve(num2,b); for(int i=0;i<63;i++) num2[i]-=num1[i]; LL ans=0; for(int i=0;i<63;i++) { ans+=num2[i]/2; num2[i+1]+=num2[i]/2; } printf("%I64d\n",ans); } return 0;}
0 0
- HDU 4588 Count The Carries(规律)
- Hdu 4588 Count The Carries (规律)
- HDU 4588 Count The Carries(数学 找规律)
- hdu 4588Count The Carries(循环节 规律题目)
- HDU 4588 Count The Carries 数位DP || 打表找规律
- HDU 4588 Count The Carries(数学 二进制 找规律啊)
- HDU-4588 Count The Carries (模拟)
- HDU 4588 Count The Carries(数学)
- HDU 4588 Count The Carries
- hdu 4588 Count The Carries
- hdu 4588 Count The Carries
- HDU 4588 Count The Carries
- HDU 4588Count The Carries
- Hdu 4588 Count The Carries(数位统计)
- HDU 4588 Count The Carries (数学-- 二进制技巧枚举)
- HDU 4588 Count The Carries 题解
- 数学题-hdu-4588-Count The Carries
- hdu 4588 Count The Carries 南京邀请赛
- 9.ATL实现IDispatch自动化接口
- 《Java中Lock和synchronized的比较和应用》
- iOS汇编教程:ARM(1)和ARM(2)
- 2016_NENU_SoftWare_Summer_ Training_1
- addChildViewController: VS addSubview:
- Hdu 4588 Count The Carries (规律)
- 这是一段神奇的代码之C
- Android加载动画系列—— GhostLoadingAnim
- Unity - 2D入门,今天我的第一个小Demo发布啦
- 关于HTML和CSS中的命名
- leetcode : Longest substring without repeating characters
- 求a+aa+aaa+......
- php接收ios上传图片的写法
- VS2012部分快捷键