原题链接: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. RAID与LVM磁盘阵列技术

    RAID(Redundant Array of Independent Disks,独立冗余磁盘阵列) RAID概念: RAID技术通过把多个硬盘设备组合成一个容量更大.安全性更好的磁盘阵列,并把数据 ...

  2. 连续小波变换(CWT)

    整理下时频分析变换的方法,遇见好的文章就记录下来了,本篇博客参考知乎https://www.zhihu.com/topic/19621077/top-answers上的一个回答,自己手敲一遍,增强记忆 ...

  3. Hyper-V 网络虚拟化技术细节

    Hyper-V 网络虚拟化技术细节 适用对象:Windows Server 2012 R2 服务器虚拟化能让多个服务器实例在同一台物理主机上同步运行,但各个服务器实例都是相互独立的. 每台虚拟机的运作 ...

  4. Android输入法弹出时覆盖输入框问题

    本文来自网易云社区 作者:孙有军 当一个activity中含有输入框时,我们点击输入框,会弹出输入法界面,整个界面的变化效果与manifest中对应设置的android:windowSoftInput ...

  5. 【Climbing Stairs】cpp

    题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...

  6. leetcode 【 Majority Element 】python 实现

    题目: Given an array of size n, find the majority element. The majority element is the element that ap ...

  7. git和github基础入门

    一.git: 1.安装配置git: 1.1从官网或者该网址处下载:https://pan.baidu.com/s/1kU5OCOB#list/path=%2Fpub%2Fgit 1.2安装,一路nex ...

  8. gcc学习记录

    -Wall: 使输出中包含警告信息,提示一些可以避免的错误.如果没有错误,则不会输出信息. -o:后面加上可执行文件的名字.如果不加-o选项,会默认生成a.out可执行文件.举例:gcc -Wall ...

  9. server.xml属性概念

    # system Processers为系统可用的线程数,一般和CPU核心线程数相同 BufferPool 是由BufferChunk组成. BufferPool的总大小为BufferChunkSiz ...

  10. ALPHA(四)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:何家伟 组员8:政演 组员9:鸿杰 组员10:刘一好 组员:何宇恒 展示组内最新 ...