Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
B. Magic Stick
Recently Petya walked in the forest and found a magic stick.
Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer:
If the chosen number 𝑎 is even, then the spell will turn it into 3𝑎2;
If the chosen number 𝑎 is greater than one, then the spell will turn it into 𝑎−1.
Note that if the number is even and greater than one, then Petya can choose which spell to apply.
Petya now has only one number 𝑥. He wants to know if his favorite number 𝑦 can be obtained from 𝑥 using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave 𝑥 as it is.
Input
The first line contains single integer 𝑇 (1≤𝑇≤104) — the number of test cases. Each test case consists of two lines.
The first line of each test case contains two integers 𝑥 and 𝑦 (1≤𝑥,𝑦≤109) — the current number and the number that Petya wants to get.
Output
For the 𝑖-th test case print the answer on it — YES if Petya can get the number 𝑦 from the number 𝑥 using known spells, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
input
7
2 3
1 1
3 6
6 8
1 2
4 1
31235 6578234
output
YES
YES
NO
YES
NO
YES
YES
题意
现在给你一个数x。
如果这个数是偶数,你可以让这个数变成x/2*3。
你也可以让这个数变成x-1
问你x经过若干次变换之后,能否变成y,能输出YES,不能输出NO
题解
其实,当x大于等于4的时候,这个x就可以变成无限大了,然后让x不断减1,就可以得到y了。
其他情况我们暴力就可以。
代码
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long x,y;
map<long long,int>H;
cin>>x>>y;
while(H[x]==0){
if(x>=y){
cout<<"YES"<<endl;
return;
}
H[x]=1;
if(x%2==1)x--;
x=x/2*3;
}
cout<<"NO"<<endl;
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2015-11-14 Codeforces Round #282 (Div. 1) A. Treasure 水题
2015-11-14 hdu 5565 Clarke and baton 二分
2015-11-14 hdu 5563 Clarke and five-pointed star 水题