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 ...
随机推荐
- 题解 洛谷P4035/BZOJ1013【[JSOI2008]球形空间产生器】
题目链接在这QvQ "你要求出这个n维球体的球心坐标",这使我想到的解方程...... 先假设n=2,这是一个二维平面.设圆心的坐标为\((x,y)\),有两个坐标\((a_1,b ...
- Yii 2.0 query模式语法
项目使用Yii 2.0版本开发,个人一直喜好使用(new \yii\db\Query())模式操作数据,把增.删.查.改这4种情况的写法整理出来,方便查阅和记忆. 增加 - insert use Yi ...
- node函数assert()详解
assert.ok() 的别名. const assert = require('assert'); assert(true); // OK assert(1); // OK assert(false ...
- 查看FPM在你的机子上的平均内存占用情况
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n" ...
- Data of Ch5 --Dual rotor
* Results *Conclusion*- little effect of rear rotor on Cp_1- Cp1 is independent of TI** TI effect on ...
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- Lucene实现全文检索的流程
[索引和搜索流程图] 对要索引的原始内容进行索引构建一个索引库,索引过程包括:确定原始内容即要搜索的内容->采集文档->创建文档->分析文档->索引文档. 从索引库中搜索内容, ...
- nativeLibraryDirectories=[/data/app/com.lukouapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libxxxx.so
一开始我遇到的问题是,如果手机有SD卡槽,则不管有没有插卡,都会闪退,打日记后发现是找不到so文件.报错日记如下: nativeLibraryDirectories=[/data/app/com.lu ...
- wps填充1到1000
A1单元格1 ,选中,填充,序列,确定
- 讨论几种数据列Column的特性(上)
之前笔者写过一个系列<索引列的usable和visible>(http://space.itpub.net/17203031/viewspace-688135),详细讨论了索引列的usab ...