原题链接:http://codeforces.com/contest/584/problem/C

题意:

定义$f(s1,s2)$为$s1,s2$不同的字母的个数。现在让你构造一个串$s3$,使得$f(s1,s3)=f(s2,s3)=t$。

题解:

设$s1,s2$共有$a$个相同的字母,共有$b$个不同的字母。现在在这$a$个相同的字母中,我让$s3$有$x$个字母和$s1,s2$不同;在这$b$个不同的字母中,我让$s3$有$y$个字母和$s1,s2$都不相同,有$z$个字母和$s1$不同。则我们可以得到以下的约束关系:

$$f(s1,s3)=x+y+z=t$$

$$f(s2,s3)=x+y+(b-y-z)=x+b-z=t$$

$$x \in [0,a]$$

$$y \in [0,b]$$

$$z \in [0,b]$$

$$y+z \in [0,b]$$

然后通过枚举$x$,检查$y,z$就能得到答案了。

代码:

#include<iostream>
#include<cstring>
#include<string>
#define MAX_N 100005
using namespace std; int n,t;
string s1,s2; int ans[MAX_N]; int main() {
cin.sync_with_stdio(false);
cin >> n >> t >> s1 >> s2;
int a = , b = ;
for (int i = ; i < n; i++) {
a += (s1[i] == s2[i]);
b += (s1[i] != s2[i]);
}
for (int x = ; x <= a; x++) {
int z = b + x - t;
int y = t - z - x;
if (z < || z > b || y < || y > b || y + z > b)continue;
for (int i = ; i < n; i++) {
if (s1[i] == s2[i]) {
if (x)ans[i] = (s1[i] == 'z' ? 'a' : s1[i] + ), x--;
else ans[i] = s1[i];
}
else {
if (y) {
int tmp = 'a';
while (tmp == s1[i] || tmp == s2[i])tmp++;
ans[i] = tmp;
y--;
}
else if (z)ans[i] = s1[i], z--;
else ans[i] = s2[i];
}
}
for (int i = ; i < n; i++)cout << (char) ans[i];
cout << endl;
return ;
}
cout << - << endl;
return ;
}

Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理的更多相关文章

  1. Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS

    D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  3. 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 ...

  4. Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                          C. Marina and Vasya   Marina loves strings of ...

  5. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

  6. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  7. Codeforces Round #324 (Div. 2)C. Marina and Vasya

    A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...

  8. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  9. 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 ...

随机推荐

  1. SQL中的函数用法

    一.coalesce COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值.如果所有的表 ...

  2. sql中比较大小

    if object_id('tempdb..#dataOldNew1') is not null drop table #dataOldNew1 select distinct store_cd ,i ...

  3. 1026: [SCOI2009]windy数(数位dp)

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9016  Solved: 4085[Submit][Sta ...

  4. 相当牛X的java版星际游戏

    分享一款牛人用java写的经典游戏,目录结构如下: 虽然只能算一个Demo,但是用到了很多Java基础技术和算法: Java2D,双缓冲,A星寻路,粒子系统,动画效果,处理图片,Swing ui ,U ...

  5. linux环境搭建系列之svn安装

    前提: linux centOS 64位操作系统 1.root账号 2.#yum install -y subversion 出现如下报错: 尝试Telnet https://www.baidu.co ...

  6. Mybatis使用-Error attempting to get column 'type' from result set. / '255' in column '4' is outside valid range for the datatype TINYINT.

    一.遇到的问题是这样的: [RemoteTestNG] detected TestNG version 6.9.10log4j: Parsing for [root] with value=[DEBU ...

  7. windows下SecureCRT无法使用Backspace(删除键)和上下左右键

    MongoDB Shell中退格键使用的问题. 利用SecureCRT工具访问linux的时候,在使用MongoDB的交互式shell的时候,退格键(Backspace)无法使用,导致无法修改输入的字 ...

  8. 前端应该掌握的CSS实现多列等高布局

    1.引言 我们在写页面的时候,有的时候会遇到多栏布局,每个栏目里面的内容有的时候可能不一样,这样就会导致每个栏目实际的高度也是不一样的,如果每个栏目有背景颜色的,就会导致每个栏目的底部是对不齐的,用户 ...

  9. 初学Linux 命令

    查看ip:ifconfig 切换用户:us root(root为用户名) 显示当前目录:pwd 列出当前目录下所有文件:ls 进入某个目录 :cd 创建一个文件夹:mkdir 创建多个目录(当没有该父 ...

  10. 解决报错DEFAULT_INCOMPATIBLE_IMPROVEMENTS

    freemarker整合springMVC报错如下:警告: Exception encountered during context initialization - cancelling refre ...