有趣的思维题

Posted fzw1523

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有趣的思维题相关的知识,希望对你有一定的参考价值。

题目链接:https://codeforces.com/problemset/problem/282/C

 

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 p and 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.

Examples
input
Copy
11
10
output
Copy
YES
input
Copy
1
01
output
Copy
NO
input
Copy
000
101
output
Copy
NO



挺有意思的思维题,如果可以找到规律基本会c的都能写出来,但想找规律的话就只能随缘了。




规律就是只要两个字符串都有1或都没有1就是yes,我来说一下这个规律的证明,首先10或01可以变为11(读题就能看出来)然后我们就从1开始把所有的都变为1
例如:000100->00 01 00 -> 00 11 00 -> 0 01 10 0 -> 0 11 11 0 -> 01 11 10 -> 11 11 11
可以自己写几个数据找找规律
都变为1之后由于11可以变为10或01
那么我们就可以把全是1的字符串变成一个至少有一个1的字符串
比如 1111 -> 11 11 -> 01 11 -> 0 11 1-> 0 01 1-> 00 11-> 0001
这个也要自己想通。


ac代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;
char x[1001000];
char y[1001000];int main()
{
    while(~scanf("%s",x)){
        scanf("%s",y);
        int flag1=0,flag2=0;
        if(strlen(x)!=strlen(y)){
            printf("NO
");
        }
        else{
            for(int i=0;i<strlen(x);i++){
                if(x[i]==1){
                    flag1=1;
                    break;
                }
            }
            for(int i=0;i<strlen(y);i++){
                if(y[i]==1){
                    flag2=1;
                    break;
                }
            }
            if(flag1==flag2) printf("YES
");
            else printf("NO
");
        }
    }
    return 0;
}
/*
11000001
00000001
*/

 






















以上是关于有趣的思维题的主要内容,如果未能解决你的问题,请参考以下文章

有趣的 C++ 代码片段,有啥解释吗? [复制]

python [代码片段]一些有趣的代码#sort

有趣的css面试题

php 有趣的代码片段在某些时候可能会有用。

数学题目

3W+字长文深度总结|程序员面试题精华版集合(内附思维导图)!