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的更多相关文章

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

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

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

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

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

  4. Codeforces Round #324 (Div. 2)

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

  5. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

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

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

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

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

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

随机推荐

  1. Gas Station,转化为求最大序列的解法,和更简单简单的Jump解法。——贪心、转化

    Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...

  2. gameplay理解

    Camera视角:确定显示的视场及视角. Game:显示的基类.静态单例模式.但是获取方式很奇怪. Game::getInstance得到的是__gameInstance,但是__gameInstan ...

  3. 怎样使用ListView?

    怎样使用ListView? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFC ...

  4. UVa 12377 - Number Coding

    题目:一个数能够用一种素数元素的个数表示的形式,43560=23×32×51×112表示成41223: 第一个数是素因子的种类,第二个是每一个素因子的个数递增排列.给你一个这样的形式的串, 问原来的数 ...

  5. hive cli 启动缓慢问题

    hive-0.13.1启动缓慢的原因 发现时间主要消耗在以下3个地方: 1. hadoopjar的时候要把相关的jar包上传到hdfs中(这里大概消耗5s,hive0.11一样,这个地方不太好优化) ...

  6. openwrt gstreamer实例学习笔记(五. gstreamer BUS)

    1)概述 BUS(总线) 是一个简单的系统,它采用自己的线程机制将一个管道线程的消息分发到一个应用程序当中.总线的优势是:当使用GStreamer的时候,应用程序不需要线程识别,即便GStreamer ...

  7. WTF

    WTF ,luna黑色主题比较sublime 还是差点!

  8. 2016/06/10 日历插件 Datepicker

    显示效果: <!doctype html> <html lang="en"> <head> <meta charset="utf ...

  9. 从小姐姐博客那里看到的流光文字(CSS3 animate)

    对于流光文字,大家并不陌生,毕竟我们都经历过非主流的时代.你们卟懂绯紸流!色彩缤纷的QQ空间...... 还记得那些炫酷的签名档,或者那些炫酷的动态头像.不过大家对于流光文字的印象还是图片.那么在网页 ...

  10. LWIP在STM32上的移植

    本文做记录摘抄,加上自己的体会: 文章标题:STM32使用LWIP实现DHCP客户端 http://www.cnblogs.com/dengxiaojun/p/4379545.html 该文章介绍了几 ...