zoukankan      html  css  js  c++  java
  • 有趣的思维题

    题目链接: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
    */
  • 相关阅读:
    模仿Linux内核kfifo实现的循环缓存
    FFmpeg + SoundTouch实现音频的变调变速
    C++标准库实现WAV文件读写
    PHP写的一个轻量级的DI容器类(转)
    android App抓包工具的应用(转)
    Dell 服务器阵列扩容【经验分享(转)】
    hexo静态博客的安装及应用实践记录
    centos 6.5 升级php到5.6.17版本
    前端框架记录
    Virtual DOM 虚拟DOM的理解(转)
  • 原文地址:https://www.cnblogs.com/fzw1523/p/9797736.html
Copyright © 2011-2022 走看看