欢迎光临散文网 会员登陆 & 注册

牛客竞赛题目讲解_或与异或

2022-05-03 14:48 作者:Clayton_Zhou  | 我要投稿

// https://ac.nowcoder.com/acm/contest/11225/E


#include<bits/stdc++.h>

using namespace std;

#define LL long long 

LL a,b,tar;

set<pair<LL,LL>> st;

bool dfs(LL x,LL y){

    if(x==tar||y==tar)return 1;

    if(x<y)swap(x,y); 

    if(st.count({x,y}))return 0;

    st.insert({x,y});

    if(dfs(x|y,x)||dfs(x|y,y)||dfs(x&y,x)||dfs(x&y,y)

       ||dfs(x^y,x)||dfs(x^y,y))return 1;

    return 0;

}

int main(){

    int T;cin>>T;

    while(T--){

        cin>>a>>b>>tar;

        st.clear();

        if(dfs(a,b))cout<<"YES\n";

        else cout<<"NO\n";

    }

}


牛客竞赛题目讲解_或与异或的评论 (共 条)

分享到微博请遵守国家法律