• 【巧妙】【3-21个人赛】Problem C 01串



    Problem C

    Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
    Total Submission(s) : 167   Accepted Submission(s) : 29

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    Problem Description

    调皮的萌萌喜欢在传输的数据上做改动,具体方法如下:
    在一串由0、1组成的数据中,执行任意次数(可能为0次)的如下的操作:
    任意选取相邻的两位a、b,把这两位变成a or b、a xor b。
    比如:10可变为11,11可变为01或10.
    给你两个01串s1、s2,请你s2是否有可能是萌萌用s1改动的来的数据。

    Input

    输入数据包含多组测试数据。
    每组数据包含两行0、1组成的字符串s1、s2。

    Output

    对于每组数据,如果s2可由s1改动而来,输出“YES”,否则输出“NO”。

    Sample Input

    11
    10
    1
    01
    000
    101
    

    Sample Output

    YES
    NO
    NO

    SB了 很容易发现一个规律 01 11 10 可以互相转换
    所以一个串只要里面有个1  都可以变成00000000000000000001
    所以 只需要判断一下 2个串 
     是否都有1和长度相等即可

    代码如下:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdlib.h>
    #include <limits.h>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    
    char stra[100005],strb[100005];
    
    int main()
    {
      //  freopen("a.in","r",stdin);
        //freopen("b.out","w",stdout);
    	while(~scanf("%s%s",stra,strb)){
    		int lena=strlen(stra),lenb=strlen(strb);
    		if(lena!=lenb){
    			puts("NO");
    			continue;
    		}
    		int acnt=0,bcnt=0;
    		for(int i=0;i<lena;i++){
    			if(stra[i]=='1')acnt++;
    			if(strb[i]=='1')bcnt++;
    		}
    		if(acnt==0&&bcnt==0){
    			puts("YES");
    		}else if(acnt&&bcnt){
    			puts("YES");
    		}else{
    			puts("NO");
    		}
    	}
        return 0;
    }
    





  • 相关阅读:
    python 类和实例
    python 装饰器
    *args和**kwargs:
    定义函数
    python 调用函数
    python lambda表达式
    java-commons-HttpClient超时设置setConnectionTimeout和setSoTimeout
    python 获取响应头
    Freesshd Permission denied (publickey).
    update 嵌套优化
  • 原文地址:https://www.cnblogs.com/zy691357966/p/5480408.html
Copyright © 2020-2023  润新知