原题链接: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. AngularJS 之1-初识

    摘要:本文主要记录第一次接触AngularJS的笔记,现在在我面前就是一张白纸+一点简单的html知识. 1.首先在<head>中加 <script src="一个网址(具 ...

  2. OpenCV学习笔记(五) 文件存取

    转自输入输出XML和YAML文件 To be filled

  3. TCP报文格式,TCP的三次握手和四次挥手&hosts文件

    1.TCP报文格式 TCP报头中的源端口号和目的端口号同IP数据报中的源IP与目的IP唯一确定一条TCP连接 序号(4字节=32位): 37 59 56 75 用来标识TCP发端向TCP收端发送的数据 ...

  4. vrpie在Visio Studio 中无法调试的问题

    最近这这几天一直在研究vrpie,之前不能调试,一调试就出问题,打开那个生成的htm文件是没问题的,最初的解决方法是不通过调试来打可那个htm页面,但是这样比较麻烦,因为经常需要和服务器交互,就只能用 ...

  5. day05_07 标志位讲解

    continue: 需求:大于5才打印 for i in range(10): if i<6 : continue print(i) continue作用:结束本次循环,继续下次循环 break ...

  6. [oldboy-django][6其他]navicat远程登录没有权限

    day6-17-1204 # 增加远程访问mysql的权限(就是其他ip地址远程访问另外一个ip地址的数据库) -- step1 修改配置文件,bind_address, 允许所有ip地址都可以访问m ...

  7. python中 in, any 和 all用法

    in if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') any if x or y o ...

  8. 生产环境下yum的配置

    介绍在局域网里面配置本地yum源环境: 在私有云的服务器上配置本地yum源 在局域网中有多台服务器,网段为192.168.10.0/24在其中一台10.11配置本地yum源,其他服务器中的baseur ...

  9. 【bzoj3601】一个人的数论 莫比乌斯反演+高斯消元

    题目描述 题解 莫比乌斯反演+高斯消元 (前方高能:所有题目中给出的幂次d,公式里为了防止混淆,均使用了k代替) #include <cstdio> #include <cstrin ...

  10. [HDU3480] Division [四边形不等式dp]

    题面: 传送门 思路: 因为集合可以无序选择,所以我们先把输入数据排个序 然后发先可以动归一波 设$dp\left[i\right]\left[j\right]$表示前j个数中分了i个集合,$w\le ...