Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接: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 乱搞推理的更多相关文章
- 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 ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- 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 ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya set
C. Marina and Vasya Marina loves strings of ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- 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 ...
随机推荐
- Python 频繁请求问题: [Errno 104] Connection reset by peer
Table of Contents 1. 记遇到的一个问题:[Errno 104] Connection reset by peer 记遇到的一个问题:[Errno 104] Connection r ...
- 线段树[To be continued]
目录 数据结构--线段树 一.定义 二.性质 三.基本操作 0.结构体 1.建树 2.单点查询 3.单点修改 4.区间修改 5.区间查询 四.题目 单点修改.区域查询模板 五.鸣谢 学姐的Blog 百 ...
- 46、android studio第一次使用时卡在gradle下载怎么解决?
如果没法FQ或者FQ后网速慢,哥教你一个快速解决方案. 在根目录下的.gradle目录下,找到wrapper/dists目录,如果当前正在下载gradle.x.xx-all.zip,那么会发现grad ...
- 【Distinct Subsequences】cpp
题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...
- python 笔试总结
1.对比两种函数对应结果 def fn(x): if x>0: print(x) fn(x-1) ****结果****** 3 2 1 $$$$$$另外一种$$$$$$$$$ def fn(x) ...
- OgnlValueStack 源码
/* * Copyright 2002-2006,2009 The Apache Software Foundation. * * Licensed under the Apache License, ...
- mybatis经验
- Nginx概述与安装
什么是Nginx 一款服务器软件,类似于Apache.Tomcat Nginx还是一款HTTP和反向代理服务器,同时也是一个代理邮件服务器.除了实现网站发布的功能外,还可以提供负载均衡. 所谓负载均衡 ...
- 一个 Java 的 Socket 服务器和客户端通信的例子
一个 HelloWord 级别的 Java Socket 通信的例子.通讯过程: 先启动 Server 端,进入一个死循环以便一直监听某端口是否有连接请求.然后运行 Client 端,客户端发出连接请 ...
- 洛谷P3803 【模板】多项式乘法(FFT) 【fft】
题目 这是一道FFT模板题 输入格式 给定一个n次多项式F(x),和一个m次多项式G(x). 请求出F(x)和G(x)的卷积. 输出格式 第一行2个正整数n,m. 接下来一行n+1个数字,从低到高表示 ...