当前位置:网站首页>C. Binary String Reconstruction
C. Binary String Reconstruction
2022-08-09 21:55:00 【秦小咩】
C. Binary String Reconstruction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Consider the following process. You have a binary string (a string where each character is either 0 or 1) ww of length nn and an integer xx. You build a new binary string ss consisting of nn characters. The ii-th character of ss is chosen as follows:
- if the character wi−xwi−x exists and is equal to 1, then sisi is 1 (formally, if i>xi>x and wi−x=wi−x= 1, then si=si= 1);
- if the character wi+xwi+x exists and is equal to 1, then sisi is 1 (formally, if i+x≤ni+x≤n and wi+x=wi+x= 1, then si=si= 1);
- if both of the aforementioned conditions are false, then sisi is 0.
You are given the integer xx and the resulting string ss. Reconstruct the original string ww.
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
Each test case consists of two lines. The first line contains the resulting string ss (2≤|s|≤1052≤|s|≤105, each character of ss is either 0 or 1). The second line contains one integer xx (1≤x≤|s|−11≤x≤|s|−1).
The total length of all strings ss in the input does not exceed 105105.
Output
For each test case, print the answer on a separate line as follows:
- if no string ww can produce the string ss at the end of the process, print −1−1;
- otherwise, print the binary string ww consisting of |s||s| characters. If there are multiple answers, print any of them.
Example
input
Copy
3 101110 2 01 1 110 1
output
Copy
111011 10 -1
=========================================================================
我们先满足必须是0的位置,然后为了尽可能满足其余1的情况,我们让剩余位置全是1即可,然后在进行无解的判断,条件就按照题目给的写就够了
# include<iostream>
# include<string.h>
using namespace std;
char s[100000+10],t[100000+10];
int main ()
{
int n;
cin>>n;
while(n--)
{
scanf("%s",s+1);
int x;
cin>>x;
for(int i=1;i<=strlen(s+1);i++)
{
t[i]='1';
}
for(int i=1;i<=strlen(s+1);i++)
{
if(s[i]=='0')
{
if(i-x>=1)
t[i-x]='0';
if(i+x<=strlen(s+1))
t[i+x]='0';
}
}
int flag=0;
for(int i=1;i<=strlen(s+1);i++)
{
if(s[i]=='1')
{
if(!((i-x>=1&&t[i-x]=='1')||(i+x<=strlen(s+1)&&t[i+x]=='1')))
{
flag=1;
break;
}
}
else
{
if((i-x>=1&&t[i-x]=='1')||(i+x<=strlen(s+1)&&t[i+x]=='1'))
flag=1;
}
}
if(flag)
{
cout<<"-1"<<endl;
}
else
{
for(int i=1;i<=strlen(s+1);i++)
{
cout<<t[i];
}
cout<<endl;
}
}
return 0;
}
边栏推荐
- navicat 快捷键
- leetcode 38. 外观数列
- 任务流执行器是如何工作的?
- Liver all night to write a thirty thousand - word all the commands the SQL database, function, speaks clearly explain operators, content is rich, proposal collection + 3 even high praise!
- TF generates uniformly distributed tensor
- 注意力引导网络用于视网膜图像分割
- Technology Sharing | How to use the JSON Schema mode of interface automation testing?
- SecureCRT background color
- APP automation test framework - UiAutomator2 introductory
- 简单问题窥见数学
猜你喜欢
台风生成,广州公交站场积极开展台风防御安全隐患排查
JS Deobfuscation - AST Restoration Case
关于ETL的两种架构(ETL架构和ELT架构)
第十七期八股文巴拉巴拉说(数据库篇)
2022年中国第三方证券APP创新专题分析
CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
为什么这么多人都想当产品经理?
腾讯继续挥舞降本增效“大刀”,外包员工免费餐饮福利被砍了
【微服务~Nacos】Nacos服务提供者和服务消费者
leetcode 38. 外观数列
随机推荐
Deceptive Dice
【服务器数据恢复】SAN LUN映射出错导致文件系统数据丢失的数据恢复案例
2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day
Basic JSON usage
【软考 系统架构设计师】案例分析⑤ 质量属性和架构评估
大型分布式存储方案MinIO介绍,看完你就懂了!
金山云地震,震源在字节?
mysql multi-table left link query
JS–比想象中简单
STC8H development (15): GPIO drive Ci24R1 wireless module
[Implementation of the interface for adding, deleting, checking, and modifying a double-linked list]
Analyze the Add() method in Fragment management from the source code
Metasploit常用命令、技术功能模块
重要的不是成为海贼王,而是像路飞一样去冒险
Evolution of MLOps
leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
ACM MM 2022 | Cloud2Sketch: Painting with clouds in the sky, AI brush strokes
LeetCode26: remove duplicates in sorted array
好未来,想成为第二个新东方
5个 Istio 访问外部服务流量控制最常用的例子,你知道几个?