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/problem/C
Description
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.
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
abc
xyc
Sample Output
HINT
题意
给你两个字符串,要求你构造出第三个字符串,使得第三个字符串和第一个字符串和第二个字符串的不同个数,都是k个
题解:
难点就是重叠的时候
只要过了下面数据就差不多了吧
3 2
abc
def
这个只要交替染色就好了
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <functional>
#include <queue>
#define N 100000+100
#define pf(x) ((x)*(x))
#define D(x) (1/x)
#define LL long long
using namespace std;
const double PI=3.141592653589793; char s1[N],s2[N],s3[N];
bool v[N];
int l,t;
int cnt;
bool s; void build()
{
cnt=;
if(cnt==t)return;
for(int i=;i<l;i++)
if(s1[i]==s2[i])
{
v[i]=true;
s3[i]=s1[i];
cnt++;
if(cnt==t) return;
}
s=true;
for(int i=;i<l;i++)
if(s1[i]!=s2[i])
{
v[i]=true;
if(s) s3[i]=s1[i];
else s3[i]=s2[i];
s=!s;
if(s) cnt++;
if(cnt==t) return;
}
} int main()
{
cin>>l>>t;
cin>>s1>>s2;
// l=strlen(s1);
t=l-t; build();
s3[l]='\0';
if(cnt<t) {cout<<"-1"<<endl;return ;}
// cout<<i<<endl;
for(int i=;i<l;i++)
if(!v[i])
{
for(int j='a';j<='z';j++)
if(s1[i]!=j && s2[i]!=j)
{s3[i]=j;break;}
} cout<<s3<<endl;
return ;
}
Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心的更多相关文章
- Codeforces Round #324 (Div. 2)C. Marina and Vasya set
C. Marina and Vasya Marina loves strings of ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...
- 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)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 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) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
随机推荐
- php 生成类的对象 $a=new test();
程序 <?php class test { ... } $a=new test(); 1.BNF 范式 start: variable '=' expr ';' expr: new_expr ; ...
- JSOI2007建筑抢修
实际上和大多这类题一样(比如wikioi上的地鼠游戏),考察的都是堆的操作 这次改完之后就算把堆的模版定下来了 悲剧的是:大根堆打成了小根堆,导致一开始一直是10分…… 按结束时间排序,(经过验证,结 ...
- c#字符串及数组操作
字符串操作(取当前时间)string time=convert.tostring(DateTime.Today).split( new char []{' '}); textbox1.text= ...
- SqlServer中decimal(numeric )、float 和 real 数据类型的区别[转]
decimal(numeric ) 同义,用于精确存储数值 float 和 real 不能精确存储数值 decimal 数据类型最 ...
- Java8 Stream API
Stream是Java8中,操作集合的一个重要特性. 从iteration到Stream操作 当你操作一个集合的时候,你通常的做法是迭代每一个元素,然后处理你想要的事情.举个例子: String co ...
- IE兼容性问题解决方案4--form表单在IE下重复提交
遇到过一种情况,点击提交按钮的时候,在IE下重复提交,而在其他浏览器下正常. 原因:button按钮不设置type时,在IE下被浏览器默认解析为type="submit",用js提 ...
- Unix System Overview
一.Unix 体系结构 由上图可以看出,内核居于最里层,Shell,Libary routines,以及Application通过系统调用(system calls)访问内核提供的功能.注意系统调用与 ...
- POJ 1113&&HDU 1348
题意:凸包周长+一个完整的圆周长.因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 模板题,之前写的Graham模板不对,WR了很多发....POJ上的AC代码 #includ ...
- 恒天云技术分享系列6 – vLan网络原理解析
转载自恒天云官网:http://www.hengtianyun.com/download-show-id-15.html Vlan网络模式优点 增加网络可扩展性 网络隔离,每个租户拥有独立的网络及vl ...
- 利用XSD配合XSLT產出特定格式Word檔案 -摘自网络
利用類別產生XSD檔 產出XSD檔的目的在於提供Word樣板設計之資料框架 在此使用微軟提供之XML Schema Definition Tool (Xsd.exe)工具產生XSD檔 1. 定義類別 ...