Codeforces Round #324 (Div. 2)C. Marina and Vasya
A的万般无奈。。。后来跑了大牛的这份代码发现,
题意是求一个序列与给定的两个序列有t个不同。
只要保证。。。对应位置就行了。。
所以处理起来非常方便。。。。。。。。。。。。。。
可是没有感觉是对应位置啊瞎几把想了一堆。后来真的是。
再后来?
我觉得非常好的就是又多了那么点见识。。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const int N=1e5+7;
bool status[N];
char Generate(char a,char b)
{
char tmp;
for(int i=0;i<26;i++)
{
tmp='a'+i;
if(tmp!=a&&tmp!=b){
return tmp;
}
}
}
int cout_dif(string a,string b,int len)
{
int res=0;
for(int i=0;i<len;i++){
if(a[i]!=b[i])
res++;
}
return res;
}
int main()
{
int n,t,dif=0;
string a,b,c;
cin>>n>>t;
cin>>a>>b;
c=string(n,'a');
vector<int>pos;
memset(status,0,sizeof(status));
for(int i=0;i<n;i++){
if(a[i]!=b[i]) // 统计给定两串的不同字符数为x。【这样特么就能统计???】
dif++;
else
status[i]=1; //标记共同的
}
if(t==dif){
for(int i=0;i<n;i++){
if(status[i]){ //如果是共同的取好
c[i]=a[i];
}
else //不同直接取个更加不同的
c[i]=Generate(a[i],b[i]);
}
}
else if(t>dif){
int cnt=0; //作为标记掉,用来考虑相同里面的t-dif那部分。
for(int i=0;i<n;i++)
{
if(status[i]){
if(cnt<(t-dif))
{
c[i]=Generate(a[i],b[i]);
cnt++;
}
else
c[i]=a[i];
}
else{ //还是要把不同个取个更加不同的
c[i]=Generate(a[i],b[i]);
}
}
}
else //保持相同部分不变,另挑(x-t)个原不同位置,使之与a串相同//同理,b串。
{
int cnt1=0,cnt2=0;
for(int i=0;i<n;i++){
if(status[i])
c[i]=a[i];
else{
if(cnt1<(dif-t)){
c[i]=a[i];
cnt1++;
}
else if(cnt2<(dif-t)){
c[i]=b[i];
cnt2++;
}
else
c[i]=Generate(a[i],b[i]);
}
}
}
if(cout_dif(a,c,n)==t&&cout_dif(b,c,n)==t)
cout<<c<<endl;
else
cout<<"-1"<<endl;
return 0;
}
Codeforces Round #324 (Div. 2)C. Marina and Vasya的更多相关文章
- 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 #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2)
CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
- 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 ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- 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 ...
随机推荐
- 安卓执行机制JNI、Dalvik、ART之间的比較 。android L 改动执行机制。
Android L默认採用ART执行环境.全然兼容64位移动处理器.Google称这将比此前的Dalvik模式性能提高两倍,可是会占用很多其它的内存空间.Android有三种执行模式:JNI.Dalv ...
- stl_内存基本处理工具
内存基本处理工具 STL定义5个全局函数.作用于初始化空间上.各自是:用于构造的construct(),用于析构的destroy(),uninitialized_copy(),uninitialize ...
- Qt:解析命令行
Qt从5.2版開始提供了两个类QCommandLineOption和QCommandLineParser来解析应用的命令行參数. 一.命令行写法 命令行:"-abc" 在QComm ...
- 【LeetCode从零单排】No 114 Flatten Binary Tree to Linked List
题目 Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 ...
- MySQL中insert ignore into, on duplicate key update,replace into,insert … select … where not exist的一些用法总结
在MySQL中进行条件插入数据时,可能会用到以下语句,现小结一下.我们先建一个简单的表来作为测试: CREATE TABLE `books` ( `id` ) NOT NULL AUTO_INCREM ...
- Android自己定义圆角ImageView
我们常常看到一些app中能够显示圆角图片.比方qq的联系人图标等等,实现圆角图片一种办法是直接使用圆角图片资源,当然假设没有圆角图片资源.我们也能够自己通过程序实现的,以下介绍一个自己定义圆角Imag ...
- javascript Array method总结
0.创建 Javascript创建数组的基本方式有两种.第一种是使用Array构造函数. var colors = new Array(); var colors = new Array(20); v ...
- MTK 手机芯片 2014 Roadmap
注:其中 A53 架构的是 64 位处理器. MT6733 魅蓝 MT6752 魅族 note 联通/移动版 MT6595 魅族 MX4
- fastdfs配置文件解析
1 tracker.conf 1.1 disabled=false 设置为false则该配置文件生效,否则屏蔽. 1.2 bind_addr= 程序监听地址,如果不设定则监听所有地址. 1.3 por ...
- JavaScript数组的某些操作(一)
在软件开发的过程中JavaScript的编程在所难免.当中对数组的操作尤为常见,这里介绍一下和JavaScript数组相关的某些操作: 1.删除并返回数组的第一个元素--shift方法: <!D ...