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
output
-1

题意:给你两个长度一样n的字符串,让你再构造一个字符串是的它与任意这给出的俩个字符串不同字母个数为t
题解:我是set乱作的,代码能力差,求谅解
///
#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=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
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,,n-)
if(a[i]==b[i])
G.insert(i);
t=n-t;
if(t>G.size())
{
int tmp=(n-G.size())/;
if(tmp<t-G.size()){cout<<-<<endl;return ;}
for(it=G.begin();it!=G.end();it++)c[*it]=a[*it];
t=t-G.size();
int flag=;int flag2=;
for(int i=;i<n;i++)
{
if(G.count(i)==&&flag&&t)
{
c[i]=a[i];
flag=;
flag2=;
}
else if(G.count(i)==&&flag2&&t)
{
c[i]=b[i];
t--;
flag=;
flag2=;
}
else if(G.count(i)==){
for(int j=;j<;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!=)
{ c[*it]=a[*it];
t--;
}else {
for(int j=;j<;j++)
if('a'+j!=a[*it]&&'a'+j!=b[*it])
{
c[*it]='a'+j;break;
}} }
for(int i=;i<n;i++)
{
if(G.count(i)==)
{
for(int j=;j<;j++)
if('a'+j!=a[i]&&'a'+j!=b[i])
{
c[i]='a'+j;break;
}
}
} } for(int i=;i<n;i++)
printf("%c",c[i]);
return ;
}

代码

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

  1. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

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

    A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...

  3. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  4. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  5. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

  6. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  7. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

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

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  9. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

随机推荐

  1. 16.04 下 ufw 防火墙的的开启、禁用、开放端口、关闭端口

    16.04 下的 ufw 防火墙相关操作使用ufw命令.通过ufw --help可以查看所有相关命令. 打开防火墙 sudo ufw enable 重启防火墙 sudo ufw reload 打开指定 ...

  2. mysql性能优化工具mysqltuner使用

    1.下载:wget --no-check-certificate https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysq ...

  3. MySQL主主配置及并行复制搭建

    思路: 两台机器互为主从. 机器1:192.168.1.160 机器2:192.168.1.164 修改两台机器的my.cnf文件,server-id,log-bin,auto-increment-i ...

  4. Poj 2187 旋转卡壳

    Poj 2187 旋转卡壳求解 传送门 旋转卡壳,是利用凸包性质来求解凸包最长点对的线性算法,我们逐渐改变每一次方向,然后枚举出这个方向上的踵点对(最远点对),类似于用游标卡尺卡着凸包旋转一周,答案就 ...

  5. Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~

                                                                              1100 - Again Array Queries ...

  6. docsearch & algolia

    docsearch & algolia The easiest way to add search to your documentation. https://community.algol ...

  7. GitHub & puppeteer & Chinese character & bug

    GitHub & puppeteer & Chinese character & bug https://github.com/GoogleChrome/puppeteer/b ...

  8. 593. Valid Square

    Problem statement: Given the coordinates of four points in 2D space, return whether the four points ...

  9. eclipse安装Aptana 插件,并设置使之能提示css,js,html,帮助编写代码

    在Eclipse 4.2 上安装 Aptana 3.2遇到的错误 就是找不到什么文件来着,我在装maven的时候也遇到了. 烦人... (这文章是我还在用eclipse的时候,为了编写js代码的时候提 ...

  10. Network(poj 3694)

    题意:一个无向图可以有重边,下面q个操作,每次在两个点间连接一条有向边,每次连接后整个无向图还剩下多少桥(注意是要考虑之前连了的边,每次回答是在上一次的基础之上) /* tarjan+LCA 先用ta ...