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. Android安全机制介绍

    Android的安全机制包含下面几个方面:      • 进程沙箱隔离机制.      • 应用程序签名机制.      • 权限声明机制.      • 訪问控制机制.      • 进程通信机制. ...

  2. react map 遍历

    1.map方法 注:map 返回的是一个新数组 class App extends Component { // constructor(props) { // super(props); // th ...

  3. Andriod 从源码的角度详解View,ViewGroup的Touch事件的分发机制

    转自:xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/21696315) 今天这篇文章主要分析的是Android的事件分发机制, ...

  4. Effective C++ 条款八 别让异常逃离析构函数

    class DBConn //这个class用来管理DBConnction对象 { public:   //自己设计一个新的DBConn接口 方法3 void close() { db.close() ...

  5. WPF窗口最大化

    做C/S应用程序的过程中,要实现的一个功能是可以编辑系统某一类表,这些表又含有不同的properties,properties数量也不相同,有二十来个的,也有一两个的,所以,popUp出来之后大小各异 ...

  6. BusHelper

    https://github.com/eltld/-BusHelper https://github.com/eltld/BusLineSAX

  7. TinyXML学习:TiXmlBase类

    TiXmlBase: 作为整个TinyXML模型的基类,除了可以提供一些实用功能外,它几乎没有什么作用 TiXmlBase的友元类: friend class TiXmlNode; friend cl ...

  8. OOP思想又一随笔

    现有类再有对象, 类:对现实世界事物的抽象表示,包括事物的状态信息(成员变量)和行为信息(成员方法).我们要让我们的计算机程序设计更有意思,也更有逻辑性,则我们的程序中对事物的描叙就必须符合真实情况, ...

  9. LeetCode题解(13)--Roman to Integer

    https://leetcode.com/problems/roman-to-integer/ 原题: Given a roman numeral, convert it to an integer. ...

  10. WebService:JAX-WS实现WebService

    WebService和Java核心技术中的RMI一样用于实现异构平台上的应用程序之间数据的交互,唯一不同的是这样的技术屏蔽了语言之间的差异.这也是其大行其道的原因. 实现WebService的技术多种 ...