C. Marina and Vasya

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/584/problem/C

Description

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 Input

3 2
abc
xyc

Sample Output

ayd

HINT

题意

给你两个字符串,要求你构造出第三个字符串,使得第三个字符串和第一个字符串和第二个字符串的不同个数,都是k个

题解:

难点就是重叠的时候

只要过了下面数据就差不多了吧

3 2

abc

def

这个只要交替染色就好了

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <functional>
#include <queue>
#define N 100000+100
#define pf(x) ((x)*(x))
#define D(x) (1/x)
#define LL long long
using namespace std;
const double PI=3.141592653589793; char s1[N],s2[N],s3[N];
bool v[N];
int l,t;
int cnt;
bool s; void build()
{
cnt=;
if(cnt==t)return;
for(int i=;i<l;i++)
if(s1[i]==s2[i])
{
v[i]=true;
s3[i]=s1[i];
cnt++;
if(cnt==t) return;
}
s=true;
for(int i=;i<l;i++)
if(s1[i]!=s2[i])
{
v[i]=true;
if(s) s3[i]=s1[i];
else s3[i]=s2[i];
s=!s;
if(s) cnt++;
if(cnt==t) return;
}
} int main()
{
cin>>l>>t;
cin>>s1>>s2;
// l=strlen(s1);
t=l-t; build();
s3[l]='\0';
if(cnt<t) {cout<<"-1"<<endl;return ;}
// cout<<i<<endl;
for(int i=;i<l;i++)
if(!v[i])
{
for(int j='a';j<='z';j++)
if(s1[i]!=j && s2[i]!=j)
{s3[i]=j;break;}
} cout<<s3<<endl;
return ;
}

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

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

                                                          C. Marina and Vasya   Marina loves strings of ...

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

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

  3. 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 ...

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

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

  5. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  6. Codeforces Round #324 (Div. 2)

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

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

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

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

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

  9. 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 ...

随机推荐

  1. Eclipse插件安装

    在线安装(一定要保证网络畅通) 更新插件: Eclipse中,Help->Install New Software...从Work with下拉列表框中选择,通过该列表框可以选择Eclipse已 ...

  2. 2009国家集训队小Z的袜子

    莫队算法? 感觉没什么优越性啊?难道就是因为在排序的时候cmp函数的不同?这样做为什么减少时限啊? 我带着疑惑敲了代码,却一直有bug…… 代码: type node=record l,r,id,x, ...

  3. window国际化文案

    越来越多的程序支持多语言切换,或者能自动适应当前系统语言,让自己开发的程序支持多语言不仅可以让自己的程序被国人使用,也能让外国程序爱好者使用.VC开发多语言程序有多种方法,或读取配置文件,或使用不同资 ...

  4. 【转】Windows搭建Eclipse+JDK+SDK的Android

    原文网址:http://blog.csdn.net/sunboy_2050/article/details/6336480 一 相关下载 (1) Java JDK下载: 进入该网页: http://j ...

  5. (九)学习CSS之margin属性

    参考: 所有浏览器都支持 margin 属性. 注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit". 定义和用法 margi ...

  6. .NET 4.0中的泛型协变和逆变

    随Visual Studio 2010 CTP亮相的C#4和VB10,虽然在支持语言新特性方面走了相当不一样的两条路:C#着重增加后期绑定和与动态语言相容的若干特性,VB10着重简化语言和提高抽象能力 ...

  7. (转载)C++lambda表达式

    (转载)http://www.cnblogs.com/L-hq815/archive/2012/08/23/2653002.html lambda表达式 C++ 语言中的lambda表达式在很多情况下 ...

  8. 非均匀B样条拟合MATLAB程序

    直接上代码,多的不再说了. %------------------非均匀B样条拟合MATLAB程序----------------- clear k=; x=load('data.txt'); [n, ...

  9. DNS (二)协议

    报文字段含义: 标识字段 由客户程序设置并由服务器返回结果.客户程序通过它来确定响应与查询是否匹配. 标志字段 协商具体的通信方式和反馈通信状态随后的 4个16 bit字段说明最后 4个变长字段中包含 ...

  10. Linux下复制粘贴快捷键

    1. 在控制台下:            1.1.鼠标选中要复制的文本,按鼠标中键,即为复制                              或者              1.2.复制命令 ...