HDU 4588Count The Carries
来源:互联网 发布:手机淘宝不能登录原因 编辑:程序博客网 时间:2024/06/06 19:29
题意:询问从a加到b 二进制进位的次数
思路:
枚举二进制,有x个1 则在当前位上有x/2个进位,对前一位的贡献是x/2
#include<stdio.h>#include<cstring>using namespace std;typedef long long ll;ll a[100][3];ll solve(ll k, int q){if(k <= 0) return 0;k++;ll ans = 0, p = 0, i;for(i = 0; k >= (1 << i); i++){ll t = k / (1 << (i + 1)) * (1 << (i)); ll tmp = k % (1 << (i + 1));if(tmp > (1 << i)) t += tmp - (1 << i);a[i][q] = t;}return ans;}int main(){ll x, b;while(~scanf("%lld%lld", &x, &b)){memset(a, 0, sizeof(a));ll ans = 0, p = 0;solve(b, 1);solve(x - 1, 2);for(int i = 0; i <= 64; i++){ans += (a[i][1] - a[i][2] + p) / 2;p = (a[i][1] - a[i][2] + p) / 2;}printf("%lld\n", ans);}return 0;}
阅读全文
0 0
- 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(数论)
- 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 计算二进制进位总数
- 设置 启动页 停留时间 IOS Swift
- Scrapy爬虫原理及实践
- 机器学习第3章第6节 : 图像的日落效果
- 微信公众平台开发简要说明 —— 基本原理
- CodeFroces gym 100781 A.Adjoin the Networks(贪心)
- HDU 4588Count The Carries
- Revit中Dynamo编程——如何保护自己的算法成果
- Elasticsearch之创建索引、删除索引、索引设置、配置分析器、自定义分析器。
- 人体骨骼关键点检测
- Linux centos7 php7 编译安装 php 扩展包 curl
- 告菲氏微积分的徒子徒孙,无穷小不是空穴来风!
- [java]微服务架构连载No4 Hystrix+Dashboard+Turbine实现断路器(限流,超时,异常...)和服务监控
- 图像中文描述
- python excel文件操作