【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

设cnt表示s1和s2不同的字符的个数
如果cnt>2*t
因为这cnt个位置肯定至少有一边不同
显然肯定会有一个f(s,S)的值大于t的
如果t

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = 50000;
static class Task{ int n,t;
String s1,s2;
StringBuilder sb;
int cnt = 0; public char v(char x,char y) {
for (char key = 'a';key<='z';key++){
if (key!=x && key!=y) return key;
}
return '2';
} public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();t = in.nextInt();
s1 = in.next();s2 = in.next();
for (int i = 0;i < n;i++) {
if (s1.charAt(i)!=s2.charAt(i)) {
cnt++;
}
}
if (cnt>2*t) {
out.println(-1);
return;
}
if (cnt>=t) {
int num = cnt-t;
int cl = 0;
for (int i = 0;i < n;i++) {
if (s1.charAt(i)==s2.charAt(i)) {
out.print(s1.charAt(i));
}else {
cl++;
if (cl<=num) {
out.print(s2.charAt(i));
}else if (cl>num && cl <=2*num) {
out.print(s1.charAt(i));
}else {
out.print(v(s1.charAt(i),s2.charAt(i)));
}
}
}
}else {
int num = t-cnt;
for (int i = 0;i < n;i++) {
if (s1.charAt(i)==s2.charAt(i)) {
if (num>0) {
num--;
out.print(v(s1.charAt(i),s2.charAt(i)));
}else {
out.print(s1.charAt(i));
}
}else {
out.print(v(s1.charAt(i),s2.charAt(i)));
}
}
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 584C】Marina and Vasya的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【22.70%】【codeforces 591C】 Median Smoothing

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【23.26%】【codeforces 747D】Winter Is Coming

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. 【149】ArcGIS Desktop 10.0 & Engine 10.0 安装及破解

    写在前面:可能会出现按照此方法无法破解的情况,那请确保您有将 ArcGIS 10.0 已经完全卸载干净,直接通过控制面板进行卸载的时候并不能将其卸载干净,需要进行更深层次的卸载,包括删除注册表,各种文 ...

  2. 10.16NOIP模拟赛

    /* 我是一个大sb */ #include<iostream> #include<cstdio> #include<cstring> #include<qu ...

  3. Android 性能优化(3)性能工具之「调试 GPU 过度绘制」Debug GPU Overdraw Walkthrough-查看哪些view过度绘制了

    Debug GPU Overdraw Walkthrough 1.In this document Prerequisites Visualizing Overdraw You should also ...

  4. C# 生成 bmp 格式的图片

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; usin ...

  5. spring-redis-data的一个坑

    事故原因: 运维报告redis内存直线上升,然后查询发现都是setrange操作,review代码,没法发现setrange操作 代码如下: redisTemplate.opsForValue().s ...

  6. working hard to be a professional coder

    1:read 2 : code 3 : 勤奋 4:技术栈 就前端主流技术框架的发展而言,过去的几年里发展极快,在填补原有技术框架空白和不足的同时也渐渐趋于成熟.未来前端在已经趋向成熟的技术方向上面将会 ...

  7. SqlServer学习-常用的sql语句-持续更新中

    1.获取数据库下的所有表名 select TABLE_NAME from information_schema.tables where TABLE_TYPE='Base TABLE' 2.随机取出1 ...

  8. (四)Mybatis总结之接口映射

    前面Mybatis是直接通过Dao层与数据交互,更好的方法是Mybatis通过接口映射方式与数据交互 1.在项目中添加maven支持(即pom.xml下添加支持) <!-- 在pom.xml下配 ...

  9. ORACLE 字符串补零

    标准函数Lpad 可以实现左补零,但是如果多于需要长度,则会截断字符串.如下:-----------------------情况一:需要补零.       SELECT LPAD ('1234' , ...

  10. PAT甲级考前整理(2019年3月备考)之二,持续更新中.....

    PAT甲级考前整理之一网址:https://www.cnblogs.com/jlyg/p/7525244.html,主要总结了前面131题的类型以及易错题及坑点. PAT甲级考前整理三网址:https ...