【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 系统管理命令 - lsof - 查看进程打开的文件
命令详解 重要星级: ★★★★★ 功能说明: 全名为 list open files,也就是列举系统中已经被打开的文件,通过 lsof 命令,就可以根据文件找到对应的进程信息,也可以根据进程信息找到进 ...
- codevs1183 泥泞的道路(01分数规划)
1183 泥泞的道路 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description CS有n个小区,并且任意小区之间都有两 ...
- 【weiphp】安装中报错
问题描述:安装的第三部报错“SQLSTATE[HY000]: General error: 2030 This command is not supported in the prepared sta ...
- Linux安装MySQL标准教程
导读: 本文主要介绍 CentOS 系统二进制安装 MySQL 5.7.23 版本的安装步骤,其他版本安装过程相似. 1.前置准备 卸载旧版MySQL 查看rpm包 rpm -qa|grep mysq ...
- CentOS 7 配置 Nginx 正向代理 http、https 最详解
手头项目中有使用到 nginx,因为使用的三方云服务器,想上外网需要购买外网IP的,可是有些需要用到外网却不常用的主机也挂个外网IP有点浪费了,便想使用nginx的反向代理来实现多台内网服务器使用一台 ...
- Android 性能优化(21)*性能工具之「GPU呈现模式分析」Profiling GPU Rendering Walkthrough:分析View显示是否超标
Profiling GPU Rendering Walkthrough 1.In this document Prerequisites Profile GPU Rendering $adb shel ...
- Linux命令(007) -- systemctl
systemctl命令是系统服务管理指令,它实际上是将service和chkconfig两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd ...
- 376 Wiggle Subsequence 摆动序列
A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...
- 在dataGridView空间中添加数据
//查询信息sql语句 string sql = "select studentName,addres from student"; SqlDataAdapter adapter ...
- Javascript中的那些bug
1. x(比如document) is not defined 不止要检查是不是没有声明变量就使用了,还要检查是不是对象的方法调用写错了!比如: alert( document.getElementB ...