codeforces1469 E. A Bit Similar
E. A Bit Similar
找到一个长度为k的串使得在s长度为k的子串中,对于所有子串答案串都至少有一位相同。也就是如果将s长度为k的子串全部按位取反,那么答案串不能与这些反串匹配。
现在问题转化成,找到一个答案串(字典序最小),不能和n−k+1n-k+1n−k+1个串匹配。
对于二进制位来说,由于n−k+1<220n-k+1<2^{20}n−k+1<220,也就是我们只需要20位就一定能过找到一个和那些串都不同的串,因此可以直接暴力枚举后面20位(k-20位都填0)
对于找到一个不与n−k+1n-k+1n−k+1匹配的串,也可以把他们哈希,然后用map记录下来,答案还是枚举,但是感觉写起来有点麻烦,就没写(不太会写)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int N=1000010;
bool ban[N];
int pre[N];
int main()
{IO;int T=1;cin>>T;while(T--){int n,k;string s;cin>>n>>k>>s;int m=0;while(m<k&&(1<<m)<=n) m++;for(int i=0;i<=n&&i<(1<<m);i++) ban[i]=0;for(int i=0;i<n;i++) pre[i+1]=pre[i]+(int)(s[i]=='0');for(int i=0;i+k-1<n;i++){if(pre[i]!=pre[i+k-m]) continue;int mask=0;for(int j=0;j<m;j++)if(s[i+k-1-j]=='0')mask^=1<<j;if(mask<=n) ban[mask]=1;}int ans=0;while(ans<(1<<m)&&ban[ans]) ans++;if(ans==(1<<m)) cout<<"NO\n";else{cout<<"YES\n";for(int i=0;i<k-m;i++) cout<<0;for(int i=m-1;i>=0;i--) cout<<(int)((ans>>i)&1);cout<<'\n';}}return 0;
}
codeforces1469 E. A Bit Similar相关推荐
- TensorFlow please use urllib or similar directly错误。
TensorFlow实现mnist书写数字分类, 在使用 from tensorflow.examples.tutorials.mnist import input_data mnist = inpu ...
- 【用深度学习搜索相似服饰】《Using Deep Learning to Find Similar Dresses》by Luis Mey
[用深度学习搜索相似服饰]<Using Deep Learning to Find Similar Dresses>by Luis Mey
- SIMILAR:现实场景中基于子模块信息度量的主动学习
来源:Deephub Imba本文约1500字,建议阅读5分钟 这是一篇被顶会 NeurIPS 2021收录的关于主动学习的论文. 这是一篇被顶会 NeurIPS 2021收录的关于主动学习的论文,作 ...
- leetcode 839 Similar String Groups
题目 Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that ...
- Finding Similar Items 文本相似度计算的算法——机器学习、词向量空间cosine、NLTK、diff、Levenshtein距离...
http://infolab.stanford.edu/~ullman/mmds/ch3.pdf 汇总于此 还有这本书 http://www-nlp.stanford.edu/IR-book/ 里面有 ...
- cursor_sharing='SIMILAR'将被废弃
根据metalink文档<ANNOUNCEMENT: Deprecating the cursor_sharing = 'SIMILAR' setting [ID 1169017.1]>在 ...
- Similar Pairs CodeForces - 1360C(图匹配+简单贪心)
题意: 现有一个定义:(1)两个数的奇偶性相同 (2)两个数的差的绝对值为1 ,即|a-b|=1 满足以上两个条件之一,就可以说两个数是相似的 先给你一个数组,让你将数组内分成多组,每组两个元素是否都 ...
- Educational Codeforces Round 76 (Rated for Div. 2) F. Make Them Similar 折半搜索
传送门 文章目录 题意: 思路: 题意: 思路: 一个显然的思路就是2302^{30}230枚举所有的xxx,让后再检查,这个复杂度显然不能接受. 又发现对于每个位置它取多少不受其他位置限制,满足可拼 ...
- TensorFlow实现mnist书写数字分类,出现please use urllib or similar directly错误。
TensorFlow实现mnist书写数字分类, 在使用 from tensorflow.examples.tutorials.mnist import input_data mnist = inpu ...
最新文章
- 设计模式 — 行为型模式 — 访问者模式
- 一道vector实现字典的题目 C++
- Java 洛谷 P1464 Function
- WGAN-GP 学习笔记
- 中国物联网产业RFID发展机遇分析
- linux终端转到目录,linux下目录及终端学习
- python3 协程 写法_理解Python的协程(Coroutine)
- 【英语学习】【English L06】U06 Banking L1 How can I save money?
- java学习第一课----java中8种基本类型
- 随想录(我熟知的几个实时操作系统)
- 中国 AI 开发者真实现状:写代码这条路,会走多久?
- mac nginx 指定php.ini,基于Mac自带nginx、php,配置php运行环境
- 国科大杨力祥老师操作系统答案总结
- 企业微信集成自建应用——踩坑记录
- Roaring Bitmap 原理及实践
- 【FPGA - 基础知识(零)】FPGA芯片资源介绍
- windows10 1909 原版纯净系统分享
- html 格式化金额显示
- 日历显示为何成了107年2月18日
- vbox 虚拟机添加usb
热门文章
- vue html引入图片,vue引入图片的几种方式
- 爱卡创誓记java刷钱_【178创誓记】快速升级:40到50级只需要两天的黄金刷
- 华为机试支持python吗_4.10华为暑期实习生机试题目,python解答
- toast弹窗_Android 开发(一):Toast弹窗与获取控件的值
- swot分析模板_什么是SWOT分析图?怎样绘制SWOT分析思维导图,这样操作很简单
- 输出螺旋数字正方形java_Java实现顺时针输出螺旋二维数组的方法示例
- 107. 二叉树的层序遍历 II and 102. 二叉树的层序遍历 023(BFS模板题打两道)
- 栈在前端中的应用,顺便再了解下深拷贝和浅拷贝!
- [JavaWeb]web相关概念回顾
- [设计模式]依赖倒转原则