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

    统计长度为5的上升序列个数, 容易想到O(n^2)的dp f[k,i]:=Σf[k-1,j] (1<=j<i,a[i]>a[j]) ans:=Σf[5,i] 但是显然会超时,需要考虑 ...

  2. C# Process.Kill() 拒绝访问(Access Denied) 的解决方案

    需求:很多时候我们需要后台运行几个Console来不停的计算数据,那么部署到客户服务器后,如果出现突发异常,程序挂掉了,那...? 解决方案:封装了一个对后台运行程序不停监测的功能,如果发现程序有异常 ...

  3. POJ 1815 Friendship ★(字典序最小点割集)

    [题意]给出一个无向图,和图中的两个点s,t.求至少去掉几个点后才能使得s和t不连通,输出这样的点集并使其字典序最大. 不错的题,有助于更好的理解最小割和求解最小割的方法~ [思路] 问题模型很简单, ...

  4. MenuInflater用法

    MenuInflater是用来加载menu布局文件的. 与LayoutInflater类似,应用程序运行时会预先加载资源中的布局文件,如果Menu布局中的资源比较多,会影响性能,所以可以选择MenuI ...

  5. ASP.NET工作笔记之一:图片上传预览及无刷新上传

    转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...

  6. UVA 11928 The Busy Dog

    题意:一只狗被拴在杆子上,从起点开始按直线依次跑到给出的点最后回到起点问绕杆子几圈,逆时针为正,顺时针为负,撞到杆子输出Ouch!. 解法:用叉积判断方向,用余弦定理求出以杆子为顶点的角,加和除以2π ...

  7. 《深入Java虚拟机学习笔记》- 第15章 对象和数组

    1.针对对象的操作码 实例化一个新对象需要通过new操作码来实现. 对象的创建 操作码 操作数 说明 new index 在堆中创建一个新的对象,将其引用压入栈 new操作码后面紧跟一个无符号16位数 ...

  8. 转载--PHP json_encode() 和json_decode()函数介绍

    转自:http://www.nowamagic.net/php/php_FunctionJsonEncode.php 转自:http://www.jb51.net/article/30489.htm ...

  9. Oracle学习网址

    Oracle Error Search: http://www.ora-error.com/ Oracle Database Error Message - Oracle Documentation: ...

  10. 位图9宫格 BitmapSlice9.jsfl

    /** * Version 1.1, May 4: fixed issue with symbols in library folders. **/ /** * BitmapSlice9 JSFL b ...