Sherlock and the Encrypted Data
题意:
对于16进制数字num,假定 $p_0,p_1,...,p_m$ 在该数字中出现过,如果有 $x = 2^{p_0} + 2^{p_1} + ... + 2^{p_m}$
且 $x \oplus num < num$ 则认为 $F(num) = 1$, 不然 $F(num) = 0$
求$\sum_{i=L}^R {F(i)}$
解法:
考虑 $F(num) = 1$ 的条件,注意到如果有 $x \oplus num < num$,相当于 $num$ 二进制的 $p_m$ 位为1。
这样考虑数位dp。
对于确定位,我们记一下最大值。
对于不确定位,我们枚举一下全局最大值 $p_m$,然后枚举一下 $p_m / 4 +1$ 位可以的16进制的值,然后快速幂+容斥算一下即可。
#include <iostream>
#include <cstdio>
#include <cstring> #define LL long long
#define N 110
#define bit(t) (1<<(t)) using namespace std; int q,num[N],dig[N]; LL qpow(LL x,int n)
{
LL ans=;
for(;n;n>>=,x=x*x) if(n&) ans=ans*x;
return ans;
} LL calc(int m,int tot,int maxnow)
{
LL ans=;
for(int t=;t>=maxnow;t--)
{
int x = t/+;
int tmp = t%;
if(x > tot) continue;
for(int S=;S<(<<);S++)
{
int now=bit(tmp);
for(int i=;i<;i++)
if(bit(i)&S) now|=bit((tmp+i+)%);
if(now > t || (dig[x]!=- && dig[x]!=now)) continue;
int cnt=m;
if(dig[x]==-) cnt--;
if(now == t || maxnow == t) ans += qpow(t+, cnt);
else ans += qpow(t+, cnt) - qpow(t, cnt);
}
}
return ans;
} LL calc(char *S,bool inc)
{
memset(num,,sizeof(num));
int tot=strlen(S);
for(int i=;i<tot;i++)
{
if(S[i]<='' && S[i]>='') num[tot-i] = S[i]-'';
else num[tot-i] = S[i]-'a'+;
}
if(inc)
{
num[]++;
for(int i=;i<=tot;i++)
if(num[i]>=) num[i]-=,num[i+]++;
if(num[tot+]) tot++;
}
for(int i=;i<=tot;i++) dig[i]=-;
LL ans = ;
int maxnow=;
for(int i=tot;i>=;i--)
{
for(int j=;j<num[i];j++)
dig[i]=j, ans += calc(i-, tot, max(maxnow,j));
dig[i]=num[i];
maxnow=max(maxnow,dig[i]);
}
return ans;
} char L[N],R[N]; int main()
{
int q;
cin>>q;
while(q--)
{
cin>>L>>R;
cout<<calc(R,)-calc(L,)<<endl;
}
return ;
}
Sherlock and the Encrypted Data的更多相关文章
- SQL ServerAlways Encrypted Data
SQL Server 提供了一个加密表上字段的功能, Encrypt Columns , 比如身份证号码,手机号码,银行账户等等敏感信息.
- TDE: Transparent Data Encryption brief introduction
1. What is TDE? Briefly speaking, TDE is used to encrypted data. 2. The benifits: Belows are come fr ...
- MSSQL-最佳实践-Always Encrypted
摘要 在SQL Server安全系列专题月报分享中,往期我们已经陆续分享了:如何使用对称密钥实现SQL Server列加密技术.使用非对称密钥实现SQL Server列加密.使用混合密钥实现SQL S ...
- Oracle 11g R2 Backup Data Pump(数据泵)之expdp/impdp工具
Oracle Data Pump(以下简称数据泵)是Oracle 10g开始提供的一种数据迁移工具,同时也被广大DBA用来作为数据库的逻辑备份工具和体量较小的数据迁移工具.与传统的数据导出/导入工具, ...
- encrypt and decrypt data
https://www.cyberciti.biz/tips/linux-how-to-encrypt-and-decrypt-files-with-a-password.html Encryptin ...
- Note: Transparent data deduplication in the cloud
What Design and implement ClearBox which allows a storage service provider to transparently attest t ...
- TENSEAL: A LIBRARY FOR ENCRYPTED TENSOR OP- ERATIONS USING HOMOMORPHIC ENCRYPTION 解读
本文记录阅读该paper的笔记,这篇论文是TenSeal库的原理介绍. 摘要 机器学习算法已经取得了显著的效果,并被广泛应用于各个领域.这些算法通常依赖于敏感和私有数据,如医疗和财务记录.因此,进一步 ...
- [MySQL Reference Manual]15. 其他存储引擎
15. 其他存储引擎 15. 其他存储引擎 15.1 设置存储引擎 15.2 MyISAM存储引擎 15.2.1 MyISAM启动选项 15.2.2 Key的空间要求 15.2.3 MyISAM表存储 ...
- 【机器学习Machine Learning】资料大全
昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...
随机推荐
- OpenCV4Android编译
http://blog.sina.com.cn/s/blog_602f87700102vdnw.html (2015-04-02 11:10:01) 转载▼ 最近的一个项目中,需要自己编译Op ...
- 在Linux的Eclipse下搭建Android环境
http://blog.csdn.net/lyonte/article/details/6407242 一.Java环境安装配置详见<在Linux下搭建Java环境>http://blog ...
- g++ 6.4编译opencv-2.4.10报错记录
fetch公司的项目进行编译,此项目依赖opencv库.由于本人一直比较偏爱fedora,但也因此给我带来了许多"乐趣"(麻烦).fedora一直走得比较前沿,g++ 6.3了 ...
- transient、volatile关键字
transient是在对象序列化的时候,不参与序列化的字段. 如LinkedList实现了Serializable,其中有变量transient int size = 0; 在Serializable ...
- jave 金额科学记数法处理
金额 :amount amount.stripTrailingZeros().toPlainString();
- 用js判断文本框中的是不是空,是否有空格
<script type="text/javascript"> function checkRoleName(){ var userName=document.getE ...
- MVC入门——增
创建数据库表如下: 生成EF模型 //------------------------------------------------------------------------------ // ...
- android studio 程序真机执行中文显示乱码
代码里中文显示正常,真机执行后中文显示乱码,解决的方法: build.gradle中加入一句 android { compileOptions.encoding = "GBK" }
- SAM4E单片机之旅——7、LED闪烁之TC中断
RTT主要用做一个全局的定时器,而且不太通用.现在尝试使用一个更为通用的定时器进行定时:定时计数器(Timer Counter, TC). TC提供了广泛的功能,主要可以分为对输入的测量,以及波形的输 ...
- Memory usage of a Java process java Xms Xmx Xmn
http://www.oracle.com/technetwork/java/javase/memleaks-137499.html 3.1 Meaning of OutOfMemoryError O ...