• codeforces 584C Marina and Vasya


    C. Marina and Vasya

     
     

    Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.

    More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

    Input

    The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).

    The second line contains string s1 of length n, consisting of lowercase English letters.

    The third line contain string s2 of length n, consisting of lowercase English letters.

    Output

    Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

    Sample test(s)
    Input
    3 2
    abc
    xyc
    Output
    ayd
    Input
    1 0
    c
    b
     1 #include<cstdio>
     2 #include<vector>
     3 #include<cmath>
     4 #include<queue>
     5 #include<map>
     6 #include<cstring>
     7 #include<algorithm>
     8 using namespace std;
     9 typedef long long ll;
    10 typedef unsigned long long ull;
    11 const int maxn=100005;
    12 int main()
    13 {
    14     int t,n;
    15     char s1[maxn],s2[maxn],s3[maxn];
    16     scanf("%d%d",&n,&t);
    17     scanf("%s%s",s1,s2);
    18     t=n-t;
    19     int k1=0,k2=0;
    20     for(int i=0;i<n;i++)
    21     {
    22         if(s1[i]==s2[i]&&(k1<t&&k2<t))s3[i]=s1[i],k1++,k2++;
    23         else if(s1[i]!=s2[i]||k1==t)
    24             for(int j=0;j<26;j++)
    25             if(s1[i]!='a'+j&&s2[i]!='a'+j)
    26             {
    27                 s3[i]=(char)('a'+j);
    28                 break;
    29             }
    30     }
    31     if(k1==t)
    32     {
    33         puts(s3);
    34         return 0;
    35     }
    36     for(int i=0;i<n;i++)
    37     {
    38         if(s1[i]==s2[i])continue;
    39         if(k1<t)
    40             s3[i]=s1[i],k1++;
    41         else if(k2<t)
    42             s3[i]=s2[i],k2++;
    43         else
    44         for(int j=0;j<26;j++)
    45         if(s1[i]!='a'+j&&s2[i]!='a'+j)
    46         {
    47             s3[i]=(char)('a'+j);
    48             break;
    49         }
    50     }
    51     if(k1<t||k2<t)puts("-1");
    52     else puts(s3);
    53     return 0;
    54 }
    Output
    -1
  • 相关阅读:
    images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.
    算法报告
    word2vec_basic.py
    Softmax_function
    Convex combination
    函数的光滑化或正则化 卷积 应用 两个统计独立变量X与Y的和的概率密度函数是X与Y的概率密度函数的卷积
    world embedding 嵌入
    dump json 显示中文问题
    dump json 显示中文问题
    perl $d = encode_utf8($r); $f = decode_json($d)
  • 原文地址:https://www.cnblogs.com/homura/p/4999324.html
Copyright © 2020-2023  润新知