当前位置:网站首页>Codeforce c.strange test and acwing
Codeforce c.strange test and acwing
2022-07-07 08:01:00 【Wawa source】
C.Strange Test— greedy + An operation


Answer key :
First we need to know ,a|b It must be greater than or equal to b Of , After using operation three, only operation two , Therefore, operation three can only be used once , So this problem turns into a++,b++, When two numbers are added to a value, they make a|b=b, Finding the value with the least number of operation steps is the answer
It's not difficult to think about this problem , It's really hard to knock code if you're not familiar with bit operation
An operation
#include <iostream>
using namespace std;
signed main()
{
int T;
int a,b;
cin>>T;
while(T--)
{
scanf("%d %d",&a,&b);
int res=1e6+2;
res=b-a;
for(int i=a;i<=b;i++)
{
int x=b;
for(int j=20;j>=0;j--)
{
// Find the first a|b==b Of b value
if(i>>j&1)
{
if(~x>>j&1)
{
x|=1<<j;
x&=~((1<<j)-1);
}
}
}
res=min(res,i-a+1+x-b);
}
cout<<res<<endl;
}
}
acwing Weekly game Two kinds of operations
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
int res=0;
signed main()
{
cin>>n>>m;
while(m>n)
{
if(m&1)res++;
m=(m+1)/2;
res++;
}
res+=n-m;
cout<<res<<endl;
}
边栏推荐
- Iterable、Collection、List 的常见方法签名以及含义
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
- [UTCTF2020]file header
- C language flight booking system
- Linux server development, MySQL transaction principle analysis
- [webrtc] m98 Screen and Window Collection
- Cnopendata American Golden Globe Award winning data
- C语言二叉树与建堆
- buuctf misc USB
猜你喜欢

Numbers that appear only once
![[unity] several ideas about circular motion of objects](/img/84/e70c6696629dbe17ace011553f43ff.png)
[unity] several ideas about circular motion of objects

Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package

buuctf misc USB

Iterable、Collection、List 的常见方法签名以及含义

【斯坦福计网CS144项目】Lab4: TCPConnection

Custom class loader loads network class

Introduction to basic components of wechat applet

Visualization Document Feb 12 16:42
![[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替](/img/e3/cceede6babae3c8a24336c81d98aa7.jpg)
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
随机推荐
Regular e-commerce problems part1
Cnopendata American Golden Globe Award winning data
Detailed explanation of Kalman filter for motion state estimation
【webrtc】m98 screen和window采集
2022焊工(初级)判断题及在线模拟考试
padavan手动安装php
[webrtc] m98 Screen and Window Collection
Linux server development, SQL statements, indexes, views, stored procedures, triggers
QT learning 26 integrated example of layout management
pytest+allure+jenkins環境--填坑完畢
Numbers that appear only once
Codeforces Global Round 19
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
[SUCTF 2019]Game
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
Live broadcast platform source code, foldable menu bar
Installing postgresql11 database under centos7
[advanced digital IC Verification] command query method and common command interpretation of VCs tool