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. CentOS安装Openfire服务

    原文::http://xiao987334176.blog.51cto.com/2202382/979677 系统是全新新安装的系统.版本号是Centos 5.6 x86 同步北京时间 # ntpda ...

  2. leetcode 刷题之路 68 Gas Station

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  3. java cup占用高分析脚本

    [was@dmgr ita-scripts]$ vi java_analys.sh   PID=$1 ; ps -mp $PID -o THREAD,tid,time | awk -F " ...

  4. ios开发之自己定义默认生成的导航栏 标题 颜色 返回button

    一 改动导航栏颜色    导航栏在哪个页面代码放在那里面 self.navigationController.navigationBar.tintColor = [UIColor colorWithR ...

  5. iOS 开发之 - 关闭键盘 退出键盘 的5种方式

    iOS 开发之 - 关闭键盘 退出键盘 的5种方式   1.点击编辑区以外的地方(UIView) 2.点击编辑区域以外的地方(UIControl) 3.使用制作收起键盘的按钮 4.使用判断输入字元 5 ...

  6. 全志Android SDK编译详解(一)

    1.编译环境说明 Linux 服务器(任意电脑都可以,建议选择配置高的)安装ubuntu 10.04 作为编译的主机,其他开发者在xp 下,通过SSH/Telent 等协议登录linux 主机进行编. ...

  7. 获取IOS应用安装列表

    原文转载至 http://blog.csdn.net/justinjing0612/article/details/8887747 转自鸟哥博客:http://blog.cnrainbird.com/ ...

  8. weblogic 修改控制台console访问路径 url

    出于安全的考虑需要对weblogic的console进行屏避,或者修改默认的访问路径,主要有两种方法:(这里针对weblogic8.1) 一.进入默认的控制台,例如“localhost/console ...

  9. 解决pyspark-linux-windowsIDE JAVA_HOME not set

    对 os.environ 赋值 ssh://root@192.168.2.51:22/usr/bin/python -u /home/data/tmp_test/trunk/personas/tmp_ ...

  10. jQuery 工具函数

    jQuery工具函数 一.$.browser对象属性 属性列表 说明 webkit webkit相关浏览器则返回true,否则返回false,如google,傲游. mozilla mozilla相关 ...