• 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/problem/C

    Description

    Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.

    More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

    Input

    The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).

    The second line contains string s1 of length n, consisting of lowercase English letters.

    The third line contain string s2 of length n, consisting of lowercase English letters.


    Output

    Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

    Sample Input

    3 2
    abc
    xyc

    Sample Output

    ayd

    HINT

    题意

    给你两个字符串,要求你构造出第三个字符串,使得第三个字符串和第一个字符串和第二个字符串的不同个数,都是k个

    题解:

    难点就是重叠的时候

    只要过了下面数据就差不多了吧

    3 2

    abc

    def

    这个只要交替染色就好了

    代码:

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    #include <stdlib.h>
    #include <map>
    #include <functional>
    #include <queue>
    #define N 100000+100
    #define pf(x) ((x)*(x))
    #define D(x) (1/x)
    #define LL long long
    using namespace std;
    const double PI=3.141592653589793;
    
    char s1[N],s2[N],s3[N];
    bool v[N];
    int l,t;
    int cnt;
    bool s;
    
    void build()
    {
        cnt=0;
        if(cnt==t)return;
        for(int i=0;i<l;i++)
        if(s1[i]==s2[i])
        {
            v[i]=true;
            s3[i]=s1[i];
            cnt++;
            if(cnt==t) return;
        }
        s=true;
        for(int i=0;i<l;i++)
        if(s1[i]!=s2[i])
        {
            v[i]=true;
            if(s) s3[i]=s1[i];
            else s3[i]=s2[i];
            s=!s;
            if(s) cnt++;
            if(cnt==t) return;
        }
    }
    
    int main()
    {
        cin>>l>>t;
        cin>>s1>>s2;
    //    l=strlen(s1);
        t=l-t;
    
        build();
        s3[l]='';
        if(cnt<t) {cout<<"-1"<<endl;return 0;}
    //    cout<<i<<endl;
        for(int i=0;i<l;i++)
        if(!v[i])
        {
            for(int j='a';j<='z';j++)
            if(s1[i]!=j && s2[i]!=j)
            {s3[i]=j;break;}
        }
    
        cout<<s3<<endl;
        return 0;
    }
  • 相关阅读:
    XAF 一对多关系<DC翻译博客二>
    XAF 在BOModel中实现接口<DC翻译博客六>
    XPO – (Gary's post)Stored Procedure Support Coming in V2010 Vol 2 Part1
    XAF 如何从Excel复制多个单元格内容到GridView
    XAF 如何实现对选择的单元格显示矩形框和多单元格的复制及粘贴
    XAF 如何扩展应用程序模型<二> 编辑ListView自动保存
    XAF 模型编辑器
    XAF 用代码扩展和自定义应用程序模型
    XAF 翻译领域构件(DC)技术目录
    XPO (Gary's post)Stored Procedure Support coming in V2010 Vol 2 (Part 2)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4858421.html
Copyright © 2020-2023  润新知