【Codeforces 584C】Marina and Vasya
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
设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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【22.70%】【codeforces 591C】 Median Smoothing
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【23.26%】【codeforces 747D】Winter Is Coming
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- Linux 系统管理命令 - uptime - 显示系统的运行时间及负载
命令详解 重要星级: ★★★☆☆ 功能说明: uptime 命令可以输出当前系统时间.系统开机到现在的运行时间.目前有多少用户在线和系统平均负载等信息 语法格式: uptime 说明: 直接执行 up ...
- Book-MySQL-Operate
创建数据库 CREATE DATABASE db_name 查看数据库 SHOW DATABASES 选择数据库 USE db_name 删除数据库 DROP DATABASE db_name 列主键 ...
- Can't install '*' from pristine store, because no checksum is recorded for this file (SVN报错)
问题:同步.cleanup都会出现下面的提示 svn: E155017: Can't install '*' from pristine store, because no checksum is r ...
- Windows平台下Oracle监听服务启动过程中日志输出
Windows平台下Oracle监听服务启动过程中日志输出记录. 日志目录:D:\app\Administrator\diag\tnslsnr\WIN-RU03CB21QGA\listener\tra ...
- web开发----jsp中通用模版的引用 include的用法
1.静态引入的示例 通过对两种用法的了解之后 我们现在 使用静态引入 因为上述原因 我的模版页中 只有div 不会有 path等定义 也不会有html标签 如下: 我的header.jsp 全 ...
- Java多线程——线程之间的协作
Java多线程——线程之间的协作 摘要:本文主要学习多线程之间是如何协作的,以及如何使用wait()方法与notify()/notifyAll()方法. 部分内容来自以下博客: https://www ...
- 引入css的四种方式
1.内联式引用:直接用在标签上,但维护成本高 style='font-size:16px;color:#000000' 2.外部连接式引用:css代码与html代码分离,便于代码重复使用 <li ...
- npm install的时候报错 npm err code 1
在学习vue的时候,npm install的时候报错 npm err code 1,当时很郁闷,是‘vue init webpack my-project’命令新建的模版项目 ,怎么会报错,第一次遇 ...
- C# 客户端读取共享目录文件
控制台应用程序 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- CommHelper
18位流水号: public static string GenerateTransId(int i) { string transId = DateTime.Now.ToString("y ...