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=0;if(cnt==t)return;for(int i=0;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=0;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 0;} // cout<<i<<endl;for(int i=0;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 0; }
Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心相关推荐
- 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 #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...
- 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 MB Submit: xxx ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
思路:因为题目说只要存在组ai?+?ai?+?n?+?ai?+?2n?≠?6就令人满意,也就是不满意的情况就是所有ai?+?ai?+?n?+?ai?+?2n?都等于6 那就用所有的情况减去不满意的情况 ...
- 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 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira(贪心)
题意: 给定N≤2000的两个序列,通过交换第一个序列变成第二个序列给定N\le 2000的两个序列, 通过交换第一个序列变成第二个序列 如果交换ai和aj,交换的代码为|i−j|,给出交换代价最小的 ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...
- Codeforces Round #301 (Div. 2) B. School Marks 构造/贪心
B. School Marks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/probl ...
- Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)
题目链接:http://codeforces.com/contest/1077/problem/B 题意:给你一长度为n的01序列.0表示当前位置的房子灯是灭的,1表示当前房子的位置灯是亮的.判断某个 ...
最新文章
- ComplexHeatmap包绘制热图(二)
- Windowsw核心编程 第13章 Windows内存结构
- mysql 至少有2个年龄大于40岁,在MySQL中计算年龄时出错?
- django弹出对话框_Django实现简单网页弹出警告代码
- 模仿黑产破解12306验证码,验证码产品的未来是?
- linux安装pgsql源码包解压,在Linux(centos)中使用源码安装pgRouting
- python变量和对象,切片列表元祖
- 大学计算机基础徐久成pdf,大学计算机基础徐久成王岁花版第7章.pptx
- React系列——React Fiber 架构介绍资料汇总(翻译+中文资料)
- mysql setautocommit_MySql 中的setAutoCommit方法
- 关于travis scott的网名_情侣网名霸气超拽有范 情侣网名霸气超拽2个字
- 连接计算机硬盘usb,使用移动硬盘时电脑显示:“如果您将此USB设备连接到高速USB2.0端口,可以提升其性能”...
- 四、RocketMq本地集群搭建:多master-slaver异步
- IOS获取屏幕分辨率
- 个体对于吸烟人群的态度
- 什么是HotSpot虚拟机
- Pycharm新建文件模板配置
- 计算机视觉中的数据流与模型训练代码总结!
- 使用Python进行Excel文件拆分
- K8s安装 遇到错误:docker-ce conflicts with 2:docker-1.13.1-208.git7d71120.el7_9.x86_64
热门文章
- linux命令别名永久生效
- jquery SELECT 操作
- NoSQL之【MongoDB】学习(二):DML和查询操作说明
- ASP.NET上传下载文件
- 树莓派上使用QT+ffmpeg进行音频编码+部署自启动+双击不启动问题
- SCI投稿中的简写(ADM,AE,EIC等)与状态解读
- Win10环境下,SecureCRT连接不上虚拟机,显示连接超时Connection time out. 而且网络连接里没有网络适配器VMnet1和VMnet8,互ping也不同。...
- ipv6 ripng配置
- Scrapy简单入门及实例讲解
- Linux下创建Django项目并访问