#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX=1e5+7; char s1[MAX],s2[MAX],s3[MAX]; char getdif(char a,char b){
for(int i=0;i<26;i++)
if('a'+i!=a&&'a'+i!=b) return 'a'+i;
} ///考虑的方式时,假设当前字符串与A字符串相同,则不同的贡献值为(0,1),如果与B相同,则贡献值为(1,0),否则为(1,1) int main(){
int n,t,cnt;
while(scanf("%d%d",&n,&t)!=EOF){
scanf("%s%s",s1+1,s2+1);
cnt=0;
for(int i=1;i<=n;i++)
if(s1[i]!=s2[i]) cnt++;
if(t>n||cnt>2*t){ ///可以发现,这两种情况是无解的
puts("-1");
continue;
}
int a,b;
if(cnt<=t) a=b=cnt;///当不同的个数少于等于要求的个数时,直接让a=b=cnt;
else
a=b=cnt/2+cnt%2;////如果在于,则可以把cnt先平分,剩下看奇偶
int lcnt=t-a;////看还差多少个可以满足,这时考虑(1,1)的方法
if(n-cnt<lcnt){///如果相同的个数<差的个数
lcnt+=lcnt-(n-cnt);///则需要从不同的个数里把原来只考虑(1,0)或(0,1)的情况改成(1,1)
cnt-=lcnt-(n-cnt);///从原来减去
a=b=cnt/2+cnt%2;///更改a,b
}
for(int i=1;i<=n;i++){
if(s1[i]==s2[i]){
if(lcnt) s3[i]=getdif(s1[i],s2[i]),lcnt--;
else s3[i]=s1[i];
}
}
for(int i=1;i<=n;i++){
if(s1[i]!=s2[i]){
if(lcnt){
s3[i]=getdif(s1[i],s2[i]),lcnt--;
cnt--;
continue;
}
if(cnt==a&&a==b) s3[i]=getdif(s1[i],s2[i]), cnt--,a--,b--;
else{
if(a>b) s3[i]=s1[i],a--; else s3[i]=s2[i],b--;
cnt--;
}
}
}
for(int i=1;i<=n;i++)
printf("%c",s3[i]);
printf("\n");
}
return 0;
}

  

CF #324 DIV2 C题的更多相关文章

  1. CF #324 DIV2 E题

    这题很简单,把目标位置排序,把目标位置在当前位置前面的往前交换,每次都是贪心选择第一个满足这样要求的数字. #include <iostream> #include <cstdio& ...

  2. CF #323 DIV2 D题

    可以知道,当T较大时,对于LIS,肯定会有很长的一部分是重复的,而这重复的部分,只能是一个block中出现次数最多的数字组成一序列.所以,对于T>1000时,可以直接求出LIS,剩下T-=100 ...

  3. CF #316 DIV2 D题

    D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  5. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  6. codeforces round 422 div2 补题 CF 822 A-F

    A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...

  7. codeforces round 421 div2 补题 CF 820 A-E

    A Mister B and Book Reading  O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...

  8. Codeforces round 419 div2 补题 CF 816 A-E

    A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...

  9. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

随机推荐

  1. [Swift通天遁地]四、网络和线程-(14)创建一个Socket服务端

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. Eclipse 添加 YAML插件

    官网:https://github.com/oyse/yedit 离线版本:(链接: https://pan.baidu.com/s/1PJzkS1tI-VigZvfbYXUh9A 密码: gfep) ...

  3. BZOJ 2001 线段树+LCT (TLE)

    同是O(nlog^2n)怎么常数差距就这么大呢,,, 同是LCT  怎么我的和Po姐姐的常数差距就这么大呢 我绝对是脑子被驴踢了才写这个垃圾算法 //By SiriusRen #include < ...

  4. 用python语言写一个简单的计算器

    假如我们有这样一个式子: 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2 ...

  5. ACM_lowbit

    lowbit Time Limit: 2000/1000ms (Java/Others) Problem Description: long long ans = 0; for(int i = 1; ...

  6. Vue初识:一个前端萌新的总结

    一.前言 时隔三年,记得第一次写博客还是2015年了,经过这几年的洗礼,我也从一个后端的小萌新变成现在略懂一点点知识的文青.如今对于前端的东东也算有一知半解,个人能力总的来说,也能够独立开发产品级项目 ...

  7. Windows下apache+tomcat负载均衡

    Windows下apache+tomcat负载均衡 网上已经有很多的资料,但是很多都比较零碎,需要整合一起才能搭建出理想的负载均衡,正好前段时间搭建了windows与linux下的负载均衡,在此记录, ...

  8. 浅谈Java中的hashcode方法以及equals方法

    哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有一个方法: public native int hashCode(); 根据这个 ...

  9. React Native真机调试安卓版

    React Native真机调试安卓版 一.准备工作 1.1 环境搭建 React Native中文网的文档已经非常清晰地描述了,按照步骤即可.http://reactnative.cn/docs/0 ...

  10. PHP开发之旅-验证码功能实现

    验证码这样的功能可以说是无处不在了,接下来使用php来实现验证码这样的功能,这里我是将验证码实现抽取到一个类中独立开来,那么后面如果再使用到验证码功能,直接引入该类文件并创建该类的实例,就可以使用验证 ...