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 ...
随机推荐
- Ubuntu下编译Poco库
本文主要记录下Ubuntu下编译Poco C++库的配置项以备后用.系统版本:Ubuntu 16.04,1 Poco 版本:1.9.0基本的步骤如下: 1.从官网下载最新的Poco源码,地址是:htt ...
- EasyUI基础入门之Droppable(可投掷)
怎么说呢Droppable这个单词究竟是什么意思,准确来说easyui作者究竟要表达什么意思,还是不大好拿捏的.只是没关系,没有必要纠结与这些细枝末节的东西,依据官网的demo效果,就简单的将之定义为 ...
- python--网络编程--socket
网络通信标准---网络协议 互联网协议--osi七层协议 五层协议:应用层:应用层.表示层.会话层 传输层:传输层 网络层:网络层 数据链路层:数据链路层 物理层: ...
- PE添加Style
1. <style id="NumberStyle"> <setting> <param name="option"> ...
- DotNetBar MessageBoxEx 显示中文 显示office2007风格
MessageBoxEx显示消息的时候按钮是中文的解决这个问题设置 MessageBoxEx的UseSystemLocalizedString属性为 true. MessageBoxEx.UseSys ...
- php 去除html标记-strip_tags和htmlspecialchars的区别
strip_tags 去掉 HTML 及 PHP 的标记. 语法: string strip_tags(string str); 传回值: 字串 函式种类: 资料处理 内容说明 本函式可去掉字串中包含 ...
- Storage,Memcache,KVDB都是存储服务,如何区分何时用何种服务
Storage :是SAE为开发者提供的分布式文件存储服务,用来存放用户的持久化存储的文件.用户需要先在在线管理平台创建Domain(相当于一级子目录). Storage为开发者提供分布式文件存 ...
- Dynamic Language Runtime (DLR) 初深
本文主要包括两个内容:DLR在.Net中的位置和一次DLR的调用过程. 1. DLR在. Net 中的位置 图1 DLR 包括哪些内容? 1. Expression Tree(表达式树). 2. Dy ...
- Presenting view controllers on detached view controllers is discouraged
本文转载至 http://www.xuebuyuan.com/2117943.html Presenting view controllers on detached view controllers ...
- 在图片上加字符-base64转图片-图片转base64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...