HDU 4588 Count The Carries 题解
来源:互联网 发布:淘宝美工是做什么工作 编辑:程序博客网 时间:2024/06/05 16:34
题意:计算依次将a-b的数相加的过程中进位的次数。
思路:统计 a-b的所有数二进制的各个位上1的个数,然后像十进制加法那样计算进位的次数、、、
(比如十进制每进一次位呢,就得像前一位加一,那么最后向前一位进了多少就发生了多少次进位,二进制同理)
由此可以看出下面calc()函数的规律;
/*1 12 103 114 1005 1016 1107 1118 10009 100110 101011 101112 110013 110114 111015 1111由此可以看出下面calc()函数的规律;*/
#include <stdio.h>#include <algorithm>#include <iostream>#include <string.h>using namespace std;__int64 num1[70],num2[70];void calc(__int64 num[],__int64 n){ int tmp=1; for(int i=0;i<63;i++) num[i]=0; for(int i=0;i<63;i++){ if(n<=0) break; tmp*=2; num[i]=(n-n%tmp)/2; if(n%tmp>=tmp/2) num[i]+=tmp/2; else num[i]+=n%tmp; n=n-tmp/2; }}int main(){ __int64 a,b; while(~scanf("%I64d %I64d",&a,&b)){ __int64 ans=0; calc(num1,a-1); calc(num2,b); for(int i=0;i<63;i++) num2[i]=num2[i]-num1[i]; for(int i=0;i<62;i++){ ans+=num2[i]/2; num2[i+1]+=num2[i]/2; } printf("%I64d\n",ans); } return 0;}
- 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(数论)
- Count The Carries - HDU 4588 水题
- 【瞎搞】 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 计算二进制进位总数
- Linux系统学习笔记:文件I/O
- java读取数据库中的错误:"Unhandled exception type SQLException"
- 一键安装 BitNamRedmine配置GIT
- Linux系统学习笔记:文件、目录、用户
- 2013年暑假小结
- HDU 4588 Count The Carries 题解
- Linux系统学习笔记:进程
- [多线程]windows线程小结
- Linux 的启动流程
- 使用双重缓冲,避免窗体中控件位置移动的时候闪烁
- Linux系统学习笔记:信号
- 札记
- bitmaiRedmine中配置QQ企业邮箱发件(亲测)
- poj 2762