• Codeforces 282C. XOR and OR


    The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.

    A Bitlandish string is a string made only of characters "0" and "1".

    BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and qp = x xor yq = x or y. Then he replaces one of the two taken characters by pand the other one by q.

    The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.

    So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.

    You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

    Input

    The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.

    It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

    Output

    Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

    由于10/01/11可以互相转换,所以

    对于1000000000...00可以看到除了全零串以外,其可以变成任意形式

    所以只要判断a和b是不是全零串就好了

    #include<bits/stdc++.h>  
    using namespace std;
    typedef long long LL;   
    #define SIZE 1005
    
    string a,b;
    int main(){  
        // freopen("test.in","r",stdin);
        ios::sync_with_stdio(false);
        cin >> a >> b;
        int len = a.length();
        if (len != b.length()){
            cout << "NO"; return 0;
        }
    
        int onea = 0,oneb = 0;
        for (int i=0;i<len;i++){
            if (a[i] == '1'){
                onea = 1; break;
            }
        }
        for (int i=0;i<len;i++){
            if (b[i] == '1'){
                oneb = 1; break;
            }
        }
    
        if ((onea && oneb) || !(onea || oneb)){
            cout << "YES";
        }
        else cout << "NO";
    
        return 0;   
    }  
    View Code
  • 相关阅读:
    django框架——十二
    django框架——十一
    请简述一下你所了解的数据源控件有哪些
    在ASP.NET中,<%= %>和<%# %>有什么区别
    请解释ASP.NET中的web页面与其隐藏类之间的关系
    什么是viewstate,能否禁用?是否所用控件都可以禁用
    WEB控件及HTML服务端控件能否调用客户端方法?如果能,请解释如何调用
    静态类和静态方法的好处
    请写出在ASP.NET中常用的几种页面间传值的方法,并说出它们的特点。
    连接数据库主要有哪几个对象
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7905708.html
Copyright © 2020-2023  润新知