zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    CUDA Error
    yolo v3 loss=nan, Avg loss=nan的一种原因
    C++ LinearRegression代码实现
    C++ 常用数学运算(加减乘除)代码实现 Utils.h, Utils.cpp(有疑问欢迎留言)
    C++ 彩色图像(RGB)三通道直方图计算和绘制,图像逆时针旋转90° 实现代码
    Leetcode 1005. Maximize Sum Of Array After K Negations
    Leetcode 1006. Clumsy Factorial
    Leetcode 617. Merge Two Binary Trees
    Leetcode 477. Total Hamming Distance
    python进制转换
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7905708.html
Copyright © 2011-2022 走看看