Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                      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 2abcxyc

output

ayd

input

1 0cb

output

-1

题意:给你两个长度一样n的字符串,让你再构造一个字符串是的它与任意这给出的俩个字符串不同字母个数为t题解:我是set乱作的,代码能力差,求谅解

///1085422276
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inf 100000
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;
}
//****************************************
#define maxn 100000+10

set<int >G;
set<int >::iterator it;
char a[maxn],b[maxn],c[maxn];
int main()
{

    int n=read();
    int t=read();
    scanf("%s%s",a,b);
    FOR(i,0,n-1)
     if(a[i]==b[i])
         G.insert(i);
         t=n-t;
    if(t>G.size())
    {
        int tmp=(n-G.size())/2;
        if(tmp<t-G.size()){cout<<-1<<endl;return 0;}
           for(it=G.begin();it!=G.end();it++)c[*it]=a[*it];
           t=t-G.size();
           int flag=1;int flag2=0;
           for(int i=0;i<n;i++)
        {
            if(G.count(i)==0&&flag&&t)
            {
                c[i]=a[i];
                flag=0;
                flag2=1;
            }
            else if(G.count(i)==0&&flag2&&t)
            {
                c[i]=b[i];
                t--;
                flag=1;
                flag2=0;
            }
            else if(G.count(i)==0){
                 for(int j=0;j<26;j++)
                    if(‘a‘+j!=a[i]&&‘a‘+j!=b[i])
                {
                    c[i]=‘a‘+j;break;
                }
            }
        }
    }
    else {
        for(it=G.begin();it!=G.end();it++)
        {
            if(t!=0)
            {  c[*it]=a[*it];
            t--;
            }else {
             for(int j=0;j<26;j++)
                    if(‘a‘+j!=a[*it]&&‘a‘+j!=b[*it])
                {
                    c[*it]=‘a‘+j;break;
                }}

        }
        for(int i=0;i<n;i++)
        {
            if(G.count(i)==0)
            {
                for(int j=0;j<26;j++)
                    if(‘a‘+j!=a[i]&&‘a‘+j!=b[i])
                {
                    c[i]=‘a‘+j;break;
                }
            }
        }

    } for(int i=0;i<n;i++)
  printf("%c",c[i]);
    return 0;
}

代码

时间: 2024-12-19 17:13:29

Codeforces Round #324 (Div. 2)C. Marina and Vasya set的相关文章

Codeforces Round #324 (Div. 2)

今天写写cf上以前的水题,找找自信 A. Olesya and Rodion 此题要求一个能被t整除的n位数,直接t为开始,后面全部为0. 当然,需要排除位数为1但t=10的情况. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int n,t,i; scanf("%d%d"

Codeforces Round #324 (Div. 2) (快速判断素数模板)

蛋疼的比赛,当天忘了做了,做的模拟,太久没怎么做题了,然后C题这么简单的思路却一直卡到死,期间看了下D然后随便猜了下,暴力了下就过了. A.找一个能被t整除的n位数,那么除了<=10以外,其他都可以用长度为n的10或100,1000 ... 来往上加几个数而得到 #include <iostream> #include <stdio.h> #include <set> #include <algorithm> #include <string.h

Codeforces Round #324 (Div. 2) D. Dima and Lisa (哥德巴赫猜想 + 暴力)

D. Dima and Lisa Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given

Codeforces Round #324 (Div. 2) E

这题贪心,考虑先放第一个,然后从第一个数在p中的位置, 不断的往前走,和在他后面的那些数组进行交换,因为这样交换可以提高最大的效率,就是说你花费了1但是使得两个点都朝他的木匾节点减少了1 #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cmath> using namespace std; const int maxn=2

Codeforces Round #324 (Div. 2) D - Dima and Lisa(哥德巴赫猜想)

1 #include<bits/stdc++.h> 2 using namespace std; 3 4 /** 5 据哥德巴赫猜想:任意一个偶数可以拆成两个质数 6 n-- 直到质数 t , n-t 是偶数 , 将n-t 拆分成两个质数 7 8 */ 9 10 bool check(int x) { 11 for (int i = 2; i * i <= x; i++) 12 if (x % i == 0) return false; 13 return true; 14 } 15 1

Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html Codeforces Round #587 (Div. 3) B - Shooting Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a ta

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿