Problem Statement

Alice has a string s of lowercase letters. The string is written on a wall.

Alice also has a set of cards. Each card contains a single letter. Alice can take any card and glue it on top of one of the letters of s. She may use any subset of cards in this way, possibly none or all of them. She is not allowed to glue new letters in front of s or after s, she can only replace the existing letters.

Alice wants to produce the lexicographically largest possible string.

You are given the string s. You are also given a string t. Each character of t is a letter written on one of the cards. Compute and return the lexicographically largest string Alice can produce on the wall while following the rules described above.

Definition

Class:

LexmaxReplace

Method:

get

Parameters:

string, string

Returns:

string

Method signature:

string get(string s, string t)

(be sure your method is public)

Limits

Time limit (s):

2.000

Memory limit (MB):

512

Stack limit (MB):

512

Notes

Given two distinct strings X and Y of the same length, the lexicographically larger one is the one that has a larger character on the first position on which they differ.

Constraints

s will contain between 1 and 50 characters, inclusive.

t will contain between 1 and 50 characters, inclusive.

s will contain only lowercase English letters (‘a’ - ‘z’).

t will contain only lowercase English letters (‘a’ - ‘z’).

Examples

0)

“abb”

“c”

Returns: “cbb”

Alice has a single card. This card contains the letter ‘c’. The optimal solution is to glue it on top of s[0], producing the string “cbb”.

1)

“z”

“f”

Returns: “z”

Here the optimal solution is to do nothing. The card with the letter ‘f’ will remain unused.

2)

“fedcba”

“ee”

Returns: “feeeba”

3)

“top”

“coder”

Returns: “trp”

4)

“xldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwlr”

“xfpidmmilhdfzypbguentqcojivertdhshstkcysydgcwuwhlk”

Returns: “zyyyzyxwwwzwvuuttxwtssvtssxrqxppqrontmmllukrkjvwlr”

【题目链接】:

【题意】



你有最多50个字符集合,

每个字符最多只能用一次;

(所有字符只包含小写字母)

然后给你一个字符串s;

让你使用这个字符集合里面的字符,去代替字符串s的每一位,使得这个字符串s的字典序达到最大;

【题解】



顺序枚举每一位,对于每一位,找一找有没有比这个字母的字典序大的字符,有的话,就用那个代替这一位上面的字母;

没有就跳过;



【Number Of WA】



0



【反思】



比较明显的题。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
//head map <char,int> dic; class LexmaxReplace
{
public:
string get(string s, string t)
{
rep1(i,0,(int) t.size()-1){
dic[t[i]]++;
}
rep1(i,0,(int) s.size()-1){
for (char key = 'z';key>=s[i]+1;key--)
if (dic[key]>0){
dic[key]--;
s[i] = key;
break;
}
}
return s;
}
};

【SRM 717 div2 B】LexmaxReplace的更多相关文章

  1. 【SRM 717 DIV2 C】DerangementsDiv2

    Problem Statement You are given two ints: n and m. Let D be the number of permutations of the set {1 ...

  2. 【SRM 717 div2 A】 NiceTable

    Problem Statement You are given a vector t that describes a rectangular table of zeroes and ones. Ea ...

  3. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  4. 【TP SRM 703 div2 250】AlternatingString

    Problem Statement A string of zeros and ones is called an alternating string if no two adjacent char ...

  5. 【TP SRM 703 div2 500】 GCDGraph

    Problem Statement You are given four ints: n, k, x, and y. The ints n and k describe a simple undire ...

  6. 【cf 483 div2 -C】Finite or not?(数论)

    链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...

  7. 【市场调研与分析】Intel发力移动安全领域——By Me at 20140613

                                                    [市场调研与分析]Intel发力移动安全领域                               ...

  8. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  9. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

随机推荐

  1. SQL 的stuff函数

    1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_expression , start , length ,character_expres ...

  2. ASP调用WebService转化成JSON数据,附json.min.asp

    首先定义SOAP数据,然后创建HTTP对象,然后使用POST提交,获取状态码为200,就说明调用成功,再进行下一步操作…… <!--#Include virtual="/Include ...

  3. Monitor (synchronization)条件变量-安全对象

    In concurrent programming, a monitor is a synchronization construct that allows threads to have both ...

  4. 人工智能,你到底是天使or魔鬼?

    人工智能的概念早在60多年前就被提出,但又一度沉寂.随着谷歌人工智能程序AlphaGo(阿尔法狗)战胜围棋世界冠军李世石,再次为世人瞩目.然而,与无限风光一起相伴而来的,还有关于人工智能的种种争议! ...

  5. 微信小程序微信支付的一些坑

    使用的是Node.js作为后端 统一下单: appid:这里的appid是调起微信支付的appid mch_id:商户号,需要注意的是商户号要与appid对应 nonce_str:Math.rando ...

  6. Vue export和import

    config/index.js export default '123456'; import strs from '@/config';   //此处直接写@config就可以, 如果是export ...

  7. CSS核心原理

    1.优先原则: 后解析的内容,会覆盖掉之前解析的内容: 同一个选择器:文件执行从上往下,后面的样式会覆盖前面的: 如下例中color最终为粉色: div { color:red; color:pink ...

  8. UVA-1347 Tour 动态规划 难以确定的状态

    题目链接:https://cn.vjudge.net/problem/UVA-1347 题意 给出按x坐标排序的几个点. 欲从最左边不回头的走到最右边,然后再返回最左边. 每个点都要被访问,且只能经过 ...

  9. [LeetCode] 455. 分发饼干 assign-cookies(贪心算法)

    思路: 尽量先将小饼干分配给胃口小的孩子,故而饼干和孩子胃口都应该先排序. python中,a.sort()只能用于a为list, sort()是可变对象的方法,无参数,无返回值,但会影响改变对象. ...

  10. linux的一页是多大

    命令 getconf PAGESIZE 结果为4096,即一页=4096字节=4KB(注意是Byte,1B=8bit) 在使用mmap映射函数时,它的实际映射单位也是以页为单位的,即不过我们把MAP_ ...