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
  • 相关阅读:
    框架
    AS常用快捷键
    AS快捷键
    AS布局篇
    Android连载4-自定义控件的单位和尺寸
    Java连载107-join方法、锁(synchronized)机制以及原理
    HTML连载81-CSS书写格式、一个手机页面的基本结构
    Android连载3-定制ListView的界面、性能优化以及绑定点击事件
    JavaScript连载3-变量内存分析、常量、数据类型
    Java连载106-sleep方法以及中断方式、yield方法
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7905708.html
Copyright © 2011-2022 走看看