D. Zookeeper and The Infinite Zoo- 打表 二进制

文章描述了一个新加坡动物园的新景点——无限动物园,这个动物园可以用一个特殊的图来表示,图中的边由二进制AND操作决定。Zookeeper有多个查询,需要判断从一个节点到另一个节点是否可以通过这些边路径。程序需要判断给定的起点和终点是否满足条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D. Zookeeper and The Infinite Zoo

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a new attraction in Singapore Zoo: The Infinite Zoo.

The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled 1,2,3,…1,2,3,…. There is a directed edge from vertex uu to vertex u+vu+v if and only if u&v=vu&v=v, where && denotes the bitwise AND operation. There are no other edges in the graph.

Zookeeper has qq queries. In the ii-th query she will ask you if she can travel from vertex uiui to vertex vivi by going through directed edges.

Input

The first line contains an integer qq (1≤q≤1051≤q≤105) — the number of queries.

The ii-th of the next qq lines will contain two integers uiui, vivi (1≤ui,vi<2301≤ui,vi<230) — a query made by Zookeeper.

Output

For the ii-th of the qq queries, output "YES" in a single line if Zookeeper can travel from vertex uiui to vertex vivi. Otherwise, output "NO".

You can print your answer in any case. For example, if the answer is "YES", then the output "Yes" or "yeS" will also be considered as correct answer.

Example

input

Copy

5
1 4
3 6
1 6
6 2
5 5

output

Copy

YES
YES
NO
NO
YES

Note

The subgraph on vertices 1,2,3,4,5,61,2,3,4,5,6 is shown below.

=========================================================================

最反感这种caodan的打表题,打表可以发现,我们每次加的是本数字有的,加完之后是一个进位操作,也就是一个数可以衍生出来无数个数字,这些数字的二进制为1的数位一定少于等于原数,且都是进位或者保留得来的,那么只需要看原数与要转化的数字二进制位即可

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;



int main()
{


     int t;
     cin>>t;

     while(t--)
     {
         int x,y;
         cin>>x>>y;

         if(x>y)
         {
             cout<<"NO"<<endl;
         }
         else if(x==y)
         {
             cout<<"YES"<<endl;
         }
         else
         {

             int cnt1=0,cnt2=0,flag=0;
             for(int i=0;i<=30;i++)
             {
                 if((x&(1ll<<i)))
                    cnt1++;
                 if((y&(1ll<<i)))
                    cnt2++;

                 if((y&(1<<i)))//需要有个进位
                 {
                     if(cnt1==0)
                     {
                         flag=1;
                         break;
                     }
                     cnt1--;
                 }
             }

             if(flag)
             {
                 cout<<"No"<<endl;
             }
             else
             {
                 cout<<"YES"<<endl;
             }

         }
     }
    return 0;
}

 

[root@localhost kafka]# export ZOOKEEPER_OPTS="-Djava.security.auth.login.config=/usr/local/kafka/config/zookeeper_jaas.conf" [root@localhost kafka]# bin/zookeeper-server-start.sh config/zookeeper.properties [2025-03-21 10:14:57,131] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) [2025-03-21 10:14:57,133] INFO autopurge.snapRetainCount set to 3 (org.apache.zookeeper.server.DatadirCleanupManager) [2025-03-21 10:14:57,133] INFO autopurge.purgeInterval set to 0 (org.apache.zookeeper.server.DatadirCleanupManager) [2025-03-21 10:14:57,133] INFO Purge task is not scheduled. (org.apache.zookeeper.server.DatadirCleanupManager) [2025-03-21 10:14:57,133] WARN Either no config or no quorum defined in config, running in standalone mode (org.apache.zookeeper.server.quorum.QuorumPeerMain) [2025-03-21 10:14:57,151] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) [2025-03-21 10:14:57,152] INFO Starting server (org.apache.zookeeper.server.ZooKeeperServerMain) [2025-03-21 10:14:57,185] INFO Server environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT (org.apache.zookeeper.server.ZooKeeperServer) [2025-03-21 10:14:57,185] INFO Server environment:host.name=localhost (org.apache.zookeeper.server.ZooKeeperServer) [2025-03-21 10:14:57,185] INFO Server environment:java.version=1.8.0_181 (org.apache.zookeeper.server.ZooKeeperServer) [2025-03-21 10:14:57,185] INFO Server environment:java.vendor=Oracle Corporation (org.apache.zookeeper.server.ZooKeeperServer) [2025-03-21 10:14:57,185] INFO Server environment:java.home=/usr/java/jdk1.8.0_181/jre (org.apache.zookeeper.server.ZooKeeperServer) [2025-03-21 10:14:57,185] INFO Server environment:java.class.path=.:{JAVA_HOME}/lib:/usr/java/jdk1.8.0_181/jre/lib::/usr/local/kafka/bin/../libs/activation-1.1.1.jar:/usr/local/kafka/bin/../libs/aopalliance-repackaged-2
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值