当前位置:网站首页>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;
}
边栏推荐
- numpy中dot函数使用与解析
- Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
- C语言二叉树与建堆
- pytest+allure+jenkins环境--填坑完毕
- Ansible
- [SUCTF 2019]Game
- The charm of SQL optimization! From 30248s to 0.001s
- Pytest+allure+jenkins environment -- completion of pit filling
- JSON data flattening pd json_ normalize
- 2022年茶艺师(中级)考试试题及模拟考试
猜你喜欢
探索干货篇!Apifox 建设思路
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
图解GPT3的工作原理
Quickly use Jacobo code coverage statistics
misc ez_ usb
Resource create package method
这5个摸鱼神器太火了!程序员:知道了快删!
Introduction to basic components of wechat applet
【经验分享】如何为visio扩展云服务图标
Shell 脚本的替换功能实现
随机推荐
What are the positions of communication equipment manufacturers?
C language flight booking system
numpy中dot函数使用与解析
QT learning 28 toolbar in the main window
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
Sign up now | oar hacker marathon phase III, waiting for your challenge
Pytorch parameter initialization
图解GPT3的工作原理
Resource create package method
Explore dry goods! Apifox construction ideas
芯片 設計資料下載
Live broadcast platform source code, foldable menu bar
[experience sharing] how to expand the cloud service icon for Visio
2022 tea master (intermediate) examination questions and mock examination
3D reconstruction - stereo correction
php导出百万数据
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
[2022 actf] Web Topic recurrence
Jenkins remote build project timeout problem
Cnopendata American Golden Globe Award winning data