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=1;for(;n;n>>=1,x=x*x) if(n&1) ans=ans*x;return ans; }LL calc(int m,int tot,int maxnow) {LL ans=0;for(int t=15;t>=maxnow;t--){int x = t/4+1;int tmp = t%4;if(x > tot) continue;for(int S=0;S<(1<<3);S++){int now=bit(tmp);for(int i=0;i<3;i++)if(bit(i)&S) now|=bit((tmp+i+1)%4);if(now > t || (dig[x]!=-1 && dig[x]!=now)) continue;int cnt=m;if(dig[x]==-1) cnt--;if(now == t || maxnow == t) ans += qpow(t+1, cnt);else ans += qpow(t+1, cnt) - qpow(t, cnt);}}return ans; }LL calc(char *S,bool inc) {memset(num,0,sizeof(num));int tot=strlen(S);for(int i=0;i<tot;i++){if(S[i]<='9' && S[i]>='0') num[tot-i] = S[i]-'0';else num[tot-i] = S[i]-'a'+10;}if(inc){num[1]++;for(int i=1;i<=tot;i++)if(num[i]>=16) num[i]-=16,num[i+1]++;if(num[tot+1]) tot++;}for(int i=1;i<=tot;i++) dig[i]=-1;LL ans = 0;int maxnow=0;for(int i=tot;i>=1;i--){for(int j=0;j<num[i];j++)dig[i]=j, ans += calc(i-1, 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,1)-calc(L,0)<<endl;}return 0; }
View Code
转载于:https://www.cnblogs.com/lawyer/p/6841820.html
Sherlock and the Encrypted Data相关推荐
- cf776G.Sherlock and the Encrypted Data
题意:对于一个16进制数x,把x的各个数位拿出来,设其为t1,t2,...,定义s(x)为2^t1|2^t2|...,如x=0x3e53,则s(x)=2^3|2^14|2^5|2^3=16424.给出 ...
- 图文解析Song首次提出的对称可搜索加密方案---《Practical Techniques for Searches on Encrypted Data》
对称可搜索加密 本文是对Song等人首次提出的可搜索加密方案Practical Techniques for Searches on Encrypted Data中的四个方案进行图文式的演示,具体预备 ...
- Computing Arbitrary Functions of Encrypted Data(论文翻译)
Computing Arbitrary Functions of Encrypted Data ** Abstract ** 作者首先提出一个问题:假如你想委托他人进行数据处理,而又不授予他对数据的访 ...
- Efficient multi-keyword ranked query over encrypted data in cloud computing (6)
正确性和隐私保护分析 Correctness and privacy-preserving analysis In-order ranking privacy Key management 使用了基于 ...
- Efficient multi-keyword ranked query over encrypted data in cloud computing (4)
现有方案 Existing solutions 最早和最新的研究云中加密数据的多关键字排序检索方案MRSE. MRSE算法 MRSE algorithm DO先要创建一个包含一一系列关键字的词典.确定 ...
- 论文笔记 | FFConv: Fast Factorized Neural Network Inference on Encrypted Data
FFConv 问题背景 同态加密神经网络 (HENN) 打包加密 主要技术 低秩矩阵分解 分解打包(Factorized Packing, FactPack) 实验结果 MNIST数据集 CIFAR- ...
- MSSQL-最佳实践-Always Encrypted
摘要 在SQL Server安全系列专题月报分享中,往期我们已经陆续分享了:如何使用对称密钥实现SQL Server列加密技术.使用非对称密钥实现SQL Server列加密.使用混合密钥实现SQL S ...
- 在Azure Data StudioSQL笔记本中使用Python脚本加密密码
This article explores the Python scripts for encrypting and decrypting passwords in SQL Server using ...
- 如何使用Entity Framework在Always Encrypted列上模拟通配符搜索
介绍 (Introduction) The title of this post should have been "How to implement wildcard search fun ...
最新文章
- 图解Hadoop hdfs的基本工作机制及相关概念
- hbase rpc这点事
- 《MySQL 8.0.22执行器源码分析(2)解读函数 ExecuteIteratorQuery》
- (2)连续存储数组的方法
- linux cpu频率软件,linux cpu频率控制
- 【带着canvas去流浪(12)】用Three.js制作简易的MARVEL片头动画(上) #华为云·寻找黑马程序员#
- android 滑动翻转动画,Android编程实现3D滑动旋转效果的方法
- TCP/IP网络编程
- Ubuntu之hadoop非分布式(单机)和伪分布式安装
- 计算机组成原理与系统结构裘雪红课后答案,计算机组成原理与系统结构课后作业答案(包健_冯建文章复嘉版).doc...
- 在CentOS 8上安装使用Firefox的视频播放功能(FFmpeg)
- 无人驾驶常用专有名词
- 自己动手编译NodeMCU固件
- 字节跳动布局游戏,打算从腾讯的碗里“抢饭吃”?
- 真实骑手数据:73万大学毕业生在送外卖
- 免费资源分享(六) Unity3D 雷达实时定位插件
- scrapy下载斗鱼主播图片
- 个人腾讯云服务器的搭建
- 使用VM安装Centos7虚拟机
- 关于手机输入法的一些点子