zoukankan      html  css  js  c++  java
  • Codeforces Round #303 (Div. 2) B. Equidistant String 水题

    B. Equidistant String

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/545/problem/B

    Description

    Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:

    We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn't equal to ti.

    As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.

    It's time for Susie to go to bed, help her find such string p or state that it is impossible.

    Input

    The first line contains string s of length n.

    The second line contains string t of length n.

    The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.

    Output

    Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).

    If there are multiple possible answers, print any of them.

    Sample Input

    0001
    1011

    Sample Output

    0011

    HINT

    题意

    给你两串只含01的字符串,然后让你构造出一组字符串,让他们的和构造出来的字符串差异都相同

    题解:

    首先看这两组有多少个位置不一样,如果是奇数,直接输出不可能,如果是偶数,那么就前一半为s,后一半为t就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    string s;
    string t;
    int main()
    {
    
        cin>>s>>t;
        int flag=0;
        int n=s.size();
        if(s==t)
        {
            cout<<s<<endl;
            return 0;
        }
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])
                flag++;
        }
        if(flag%2==1)
        {
            printf("impossible
    ");
        }
        else
        {
            flag/=2;
            for(int i=0;i<n;i++)
            {
                if(s[i]!=t[i])
                {
                    if(flag>0)
                    {
                        cout<<s[i];
                        flag--;
                    }
                    else
                        cout<<t[i];
                }
                else
                    cout<<s[i];
            }
        }
    }
  • 相关阅读:
    C嵌入汇编
    App 运营 推广相关
    POJ 3904 Sky Code
    数组的复制与动态扩展算法
    另类病毒的自删除方法
    oracle触发器中增删改查本表
    POJ 2773 Happy 2006 数学题
    Android手机便携式wifi的使用及无线数据传输(主要针对XP系统)
    Find the minimum线段树成段更新
    使用visual c++ 2005编译64位可执行文件
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4516130.html
Copyright © 2011-2022 走看看