Codeforces Round #324 (Div. 2)C. Marina and Vasya set
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. 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.
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.
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.
3 2
abc
xyc
ayd
1 0
c
b
-1 题意:给你两个长度一样n的字符串,让你再构造一个字符串是的它与任意这给出的俩个字符串不同字母个数为t
题解:我是set乱作的,代码能力差,求谅解
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 100000+10 set<int >G;
set<int >::iterator it;
char a[maxn],b[maxn],c[maxn];
int main()
{ int n=read();
int t=read();
scanf("%s%s",a,b);
FOR(i,,n-)
if(a[i]==b[i])
G.insert(i);
t=n-t;
if(t>G.size())
{
int tmp=(n-G.size())/;
if(tmp<t-G.size()){cout<<-<<endl;return ;}
for(it=G.begin();it!=G.end();it++)c[*it]=a[*it];
t=t-G.size();
int flag=;int flag2=;
for(int i=;i<n;i++)
{
if(G.count(i)==&&flag&&t)
{
c[i]=a[i];
flag=;
flag2=;
}
else if(G.count(i)==&&flag2&&t)
{
c[i]=b[i];
t--;
flag=;
flag2=;
}
else if(G.count(i)==){
for(int j=;j<;j++)
if('a'+j!=a[i]&&'a'+j!=b[i])
{
c[i]='a'+j;break;
}
}
}
}
else {
for(it=G.begin();it!=G.end();it++)
{
if(t!=)
{ c[*it]=a[*it];
t--;
}else {
for(int j=;j<;j++)
if('a'+j!=a[*it]&&'a'+j!=b[*it])
{
c[*it]='a'+j;break;
}} }
for(int i=;i<n;i++)
{
if(G.count(i)==)
{
for(int j=;j<;j++)
if('a'+j!=a[i]&&'a'+j!=b[i])
{
c[i]='a'+j;break;
}
}
} } for(int i=;i<n;i++)
printf("%c",c[i]);
return ;
}
代码
Codeforces Round #324 (Div. 2)C. Marina and Vasya set的更多相关文章
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
随机推荐
- 洛谷——P3907 圈的异或
P3907 圈的异或 无向图$dfs$找环,并判断边权异或和是否为0 #include<iostream> #include<cstdio> #include<algor ...
- [Python3网络爬虫开发实战] 3.1.1-发送请求
使用urllib的request模块,我们可以方便地实现请求的发送并得到响应,本节就来看下它的具体用法. 1. urlopen() urllib.request模块提供了最基本的构造HTTP请求的方法 ...
- hdu4428(Coder)线段树
Coder Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 查看FPM在你的机子上的平均内存占用情况
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n" ...
- 分数拆分(刘汝佳紫书P183)
枚举,由已知条件推得y大于k,小于等于2K AC代码: #include"iostream"#include"cstring"using namespace s ...
- 关于No Spring WebApplicationInitializer types detected on classpath的提示,tomcat 卡主
No Spring WebApplicationInitializer types detected on classpath 下一句:Initializing Spring root WebAppl ...
- get方法和set方法
定义一个类,该类有一个私有成员变量,通过构造方法将其进行赋初值,并提供该成员的getXXX()和setXXX()方法 提示:假设有private String name;则有 public void ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- 寒假训练3解题报告 CodeForces #148
CodeForces 148B 一道简单模拟,判断龙能够抓到公主几次,如果公主和龙同时到达公主的城堡,不算龙抓住她,因为路程除以速度可能会产生浮点数,所以这里考虑一下精度问题 #include < ...
- 【状压+状态转移】A Famous Airport Managere
https://www.bnuoj.com/v3/problem_show.php?pid=25653 [题意] 给定一个3*3的九宫格,模拟一个停机坪.第一个格子一定是'*',代表take off ...