[暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true" or "false" respectively). And every decimal number has a binary representation which is actually a series of bits. If a bit of a number is 1 and its next bit is also 1 then we can say that the number has a 1 adjacent bit. And you have to find out how many times this scenario occurs for all numbers up to N.
Examples:
Number Binary Adjacent Bits
12 1100 1
15 1111 3
27 11011 2
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer N (0 ≤ N < 231).
Output
For each test case, print the case number and the summation of all adjacent bits from 0 to N.
Sample Input
7
0
6
15
20
21
22
2147483647
Sample Output
Case 1: 0
Case 2: 2
Case 3: 12
Case 4: 13
Case 5: 13
Case 6: 14
Case 7: 16106127360
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r;
LL f[][][];
int d[];
int zhan[],top;
inline LL dfs(int now,int dat,int tot,int fp)
{
if (now==)return tot;
if (!fp&&f[now][dat][tot]!=-)return f[now][dat][tot];
LL ans=,mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
if (i==)ans+=dfs(now-,,tot,fp&&i==d[now-]);
else ans+=dfs(now-,,tot+(dat==),fp&&i==d[now-]);
}
if (!fp)f[now][dat][tot]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x<=)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)sum+=dfs(len,i,,i==d[len]);
return sum;
}
main()
{
int T=read(),cnt=;
while (T--)
{
r=read();
if (r<l)swap(l,r);
memset(f,-,sizeof(f));
printf("Case %d: %lld\n",++cnt,calc(r));
}
}
LightOj 1032
[暑假集训--数位dp]LightOj1032 Fast Bit Calculations的更多相关文章
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位dp]UESTC250 windy数
windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Inp ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- [暑假集训--数位dp]hdu5898 odd-even number
For a number,if the length of continuous odd digits is even and the length of continuous even digits ...
随机推荐
- SC || Chapter 8
栈:方法调用和局部变量的存储位置,保存基本类型 堆:在一块内存里分为多个小块,每块包含 一个对象,或者未被占用
- 判断用户ip是否在指定的一个ip段内
/** * 判断ip是否在一个ip段内 * * @param args */ public static boolean ipExistsInRange(String ip, String ipSec ...
- c++作业:递归调用,例题4.5 求第五个人的年龄
递归调用,例题4.5 求第五个人的年龄 #include <iostream> using namespace std; int age(int num){ int a; ) a=; el ...
- 监测UITextField的变化
监测UITextField的变化可以为UIControlEventEditingChanged事件添加target. 我们有时候会需要用到这个需求:输入框输入文本超过xx长度,不再允许输入其他内容! ...
- Ubuntu16.04+GTX1080配置TensorFlow并实现图像风格转换
1. TensorFlow TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统,表达了高层次的机器学习计算,大幅简化了第一代系统,并且具备更好的灵活性和可延展性. Te ...
- CentOS7系统引导顺序以及排障
引导顺序 UEFi或BIOS初始化,运行POST开机自检 选择启动设备 引导装载程序, centos7是grub2 加载装载程序的配置文件:/etc/grub.d/ /etc/default/gru ...
- Linux:FTP服务匿名用户,本地用户,虚拟用户配置
匿名用户 FTP协议占用两个端口号: 21端口:命令控制,用于接收客户端执行的FTP命令. 20端口:数据传输,用于上传.下载文件数据. 实验:匿名访问,服务器192.168.10.10 客户 ...
- Linux系统修改网卡名(eth0-3)
一.命名规则策略 规则1: 对于板载设备命名合并固件或 BIOS 提供的索引号,如果来自固件或 BIOS 的信息可读就命名,比如eno1,这种命名是比较常见的,否则使用规则2. 规则2: 命名合并固件 ...
- 教程笔记《JavaScript深入浅出》
一.数据类型 javascript是弱数据类型语言,不需要显式的定义类型,一共有如下六种数据类型 五种基本类型:number,string,boolean,null,undefined 一种复合类型: ...
- Linux安装OpenCV
sudo apt-get update sudo apt-get install git git clone https://github.com/jayrambhia/Install-OpenCV ...