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/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
abc
xyc
Sample Output
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 贪心的更多相关文章
- Codeforces Round #324 (Div. 2)C. Marina and Vasya set
C. Marina and Vasya Marina loves strings of ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...
- 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 ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- 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 ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- 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 ...
随机推荐
- poj 3694 Network(双连通分量)
题目:http://poj.org/problem?id=3694 #include <iostream> #include <cstring> #include <cs ...
- javascript 库
http://overapi.com/javascript/ 查javascript http://slimerjs.org/ 自动测试? http://www.cnblogs.com/lhb25/p ...
- 在QuickReport中实现多栏打印
如果在Treport的DataSet属性中选定一个Table,那么QuickReport每次打印详细列表(BandType=rbDetail)属性的TQRBand时,系统会自动取出一个记录供打印, ...
- NOI2002 荒岛野人
这题其实黑书上有,只是我脑残的没想起来…… 其实就是拓展欧几里得算法 我参看的题解:http://www.cnblogs.com/Rinyo/archive/2012/11/25/2788373.ht ...
- Building QT projects from the command line
/************************************************************************ * Building QT projects fro ...
- u-boot 环境变量参数设置
今天本来是烧写内核,结果一不小心把uboot也整不能用了,无奈之下只好重新烧个uboot,等都弄好以后,发现系统还是启动不了,原来是启动参数设置不对,于是找到了这篇文章,//是我添加的内容. 原文地址 ...
- C#多线程下载一个文件
这里只是说明多线程下载的理论基础,嘿嘿,并没有写多线程下载的代码,标题党了,但是我相信,看完这个代码就应该能够多线程的方式去下载一个文件了. 多线程下载是需要服务器支持的,这里并没有判断服务器不支持的 ...
- android studio 使用的一些注意,一些报错的解决方法(原创)
NDK 编译无法通过 注意看 build.gradle 里面的 有些是 ndk-build windows 上用 ndk-build.cmd Summary: gradle calls ndk-bui ...
- devexpress 中Grid 的使用:为零不显示
如果要让为0的列不显示: this.gridColumn_FAmount.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; ...
- Notepad++中调用cl.exe编译器(Windows)
Notepad++中调用cl.exe编译器(Windows) 近来在notepad++中写代码,写完后总是习惯性的想去VS里面编译一下,看看代码是否有误.但有时候一些零碎的小文件总是懒得再VS中打开, ...