CodeForces - 584C Marina and Vasya (模拟)找规律
来源:互联网 发布:阿铭linux 编辑:程序博客网 时间:2024/05/22 12:22
Description
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly tcharacters. 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
3 2abcxyc
ayd
1 0cb
-1
Source
#include<stdio.h>#include<string.h>#include<math.h>#include<map>#include<queue>#include<stack>#include<algorithm>#include<iostream>#define INF 0x3f3f3f3f#define ull unsigned long long#define long long#define IN __in64#define N 100010#define M 1000000007 using namespace std;char s[N];char a[N],b[N];int main(){int n,m,i,j,k,kk,mm,mk,la,lb,l;while(scanf("%d%d",&n,&m)!=EOF){memset(s,'\0',sizeof(s));memset(a,'\0',sizeof(a));memset(b,'\0',sizeof(b));scanf("%s%s",a,b);k=0;for(i=0;i<n;i++){if(a[i]==b[i])k++;}mm=n-k;mk=mm/2;if(2*m<mm)printf("-1\n");else if(m+k>=n){kk=m-mm;for(i=0;i<n;i++){char d;if(a[i]==b[i]){if(kk){for(d='a';d<='z';d++){if(d!=a[i]){s[i]=d;break;}}kk--;}elses[i]=a[i];}else{for(d='a';d<='z';d++){if(d!=a[i]&&d!=b[i]){s[i]=d;break;}}}}puts(s);}else{la=lb=mm-m;l=mm-la-lb;for(i=0;i<n;i++){if(a[i]==b[i])s[i]=a[i];else{if(la){s[i]=a[i];la--;}else if(lb){s[i]=b[i];lb--;}else if(l){char d;for(d='a';d<='z';d++){if(d!=a[i]&&d!=b[i]){s[i]=d;break;}}l--;}}}puts(s);}}return 0;}
- CodeForces - 584C Marina and Vasya (模拟)找规律
- Codeforces 584C Marina and Vasya
- codeforces 584C Marina and Vasya
- Codeforces 584C Marina and Vasya 【构造】
- Codeforces 584C Marina and Vasya
- CodeForces 584C - Marina and Vasya(构造)
- codeforces 584C Marina and Vasya
- Codeforces Round #324 (Div. 2) 584C. Marina and Vasya
- Codeforces 584 C Marina and Vasya【构造+贪心】
- Codeforces #324 Div2 C Marina and Vasya(构造)
- Codeforces Round #324 C Marina and Vasya
- codeforces 324# C. Marina and Vasya (贪心)
- Code Forces 584 C. Marina and Vasya(水~)
- Codeforces 584 C. Marina and Vasya (Codeforces Round #324 (Div. 2))
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- Codeforces Round #324 (Div. 2) C. Marina and Vasya
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- CodeForces - 368C Sereja and Algorithm (找规律&模拟)
- 在类中声明函数而不去定义编译通过
- POJ 3767 I Wanna Go Home【最短路floyd】
- 查找(一)史上最简单清晰的红黑树讲解
- bfs
- iOS开发数据库篇—FMDB简单介绍
- CodeForces - 584C Marina and Vasya (模拟)找规律
- java操作properties文件
- LeetCode *** 38. Count and Say
- iOS开发数据库篇—FMDB数据库队列
- MTK BT/WIFI小析
- ggplot2-为图形添加直线
- recycleView学习01
- SLT的代码(当然不是我写的,今天不小心炸出来了,纪念一下)
- Java浅复制与深复制的区别