当前位置:网站首页>Educational codeforces round 70 a question you are given two binary strings
Educational codeforces round 70 a question you are given two binary strings
2022-07-22 02:55:00 【Cold instant noodles】
Educational Codeforces Round 70 A topic You Are Given Two Binary Strings…
subject :http://codeforces.com/contest/1202/problem/A
General meaning :
Here are two binary numbers x,y, Let you choose a number k, There is a formula sk = x + y * 2^k , Definition revk yes sk In reverse order , Seeking energy bring revk Dictionary order is the smallest Of k value .
Ideas :
The topic looks very difficult at first glance, Yazi , Actually 2^k It has a wonderful use , From a binary point of view , In fact, you chose k What is the value , Is to make y It's just how many bits to the left . Then we can find out , In fact, just let y The last one in the string 1( Left to right ), De alignment x The nearest one in the string 1 Just fine . Here's an example :
Input x by 10001, y by 110,
We can see y The last 1 Aim at x Of 0, Because of our y The string can only be moved left , That is to add 0. and y The last one in the string 1 distance x String the nearest one 1 Still bad 3 distance , So we put y Shift the string left 3 position , That is to say k Value taking 3 You can see the following :
At this time, we get it through the formula revk It's the smallest dictionary order .
Code section :
#include<iostream>
#include<string.h>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main() {
int t;
while(~scanf("%d",&t)) {
while(t--) {
char s1[100005], s2[100005];
scanf("%s %s",s1,s2);
int lens1 = strlen(s1);
int lens2 = strlen(s2);
int add1, add2;
for(int i = lens2 - 1; i >= 0; i--) {
if(s2[i] == '1') {
add2 = i;
break;
}
}
int count = 0;
for(int i = add2 + lens1 - lens2; i >= 0; i--) {
if(s1[i] != '1')
count++;
else
break;
}
printf("%d\n", count);
}
}
return 0;
}
边栏推荐
猜你喜欢
From scratch implement crnn using pytorch: read training data
duilib实战1-模仿百度网盘登录界面
简单总结一下图像处理中概念
Baiyuechen research group of Fudan University is looking for postdoctoral and scientific research assistants
[Skynet] vs2019 debug Skynet (modify vs2013 project)
Ali Er Mian: what is MMAP? (not MMP)
李宏毅深度学习课程笔记 -卷积神经网络
What data problems will you encounter in the process of data governance?
pytorch入门三 数据类型与函数
bootloader系列三——核心初始化
随机推荐
云原生时代,开发者应具备这5大能力
【Skynet】vs2019调试skynet(修改vs2013工程)
文字检测篇-传统篇
Why does a very simple function crash
Codeforces Round #579 (Div. 3) A 、B、E
Web Monitoring - mjpg streamer migration
本机电脑清除DNS缓存+浏览器清除DNS缓存
2019牛客暑期多校训练营(第七场)A-String 【字符串最小表示法+暴力枚举】
函数 之装饰器
Codeforces Round #578 (Div. 2) A - Hotelier 【水题】
2019牛客暑期多校训练营(第五场)G- subsequence 1 【DP+组合数】
SVD singular value decomposition matrix compression
Teach you to upload NCBI data hand in hand, and you can learn it in the free course package!
Raspberry pie 3B builds Flink cluster
45W性能释放+2.8K OLED全面屏 华硕灵耀X 14 2022精英气质高效利器
Leetcode 111. 二叉树的最小深度
Python predicts the model code demo of the next number through the first three numbers
Depthwise Separable Convolution详解
力扣 1260. 二维网格迁移
Educational Codeforces Round 70 A题 You Are Given Two Binary Strings...