【SRM 717 div2 B】LexmaxReplace
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的更多相关文章
- 【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 ...
- 【SRM 717 div2 A】 NiceTable
Problem Statement You are given a vector t that describes a rectangular table of zeroes and ones. Ea ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 【TP SRM 703 div2 250】AlternatingString
Problem Statement A string of zeros and ones is called an alternating string if no two adjacent char ...
- 【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 ...
- 【cf 483 div2 -C】Finite or not?(数论)
链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...
- 【市场调研与分析】Intel发力移动安全领域——By Me at 20140613
[市场调研与分析]Intel发力移动安全领域 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
随机推荐
- (转载) 据说年薪30万的Android程序员必须知道的
据说年薪30万的Android程序员必须知道的帖子 标签: android 2015-03-12 16:52 28705人阅读 评论(14) 收藏 举报 Android中国开发精英 目前包括: And ...
- Android学习——LinearLayout布局实现居中、左对齐、右对齐
android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...
- pic减法进位问题
1.pic指令中subwf是 F - Wreg,且如果F>=Wreg,则C=1:如果F<Wreg,则C=0:这是由于pic的减法是加上减数的补码实现的.例如3-2,其实是3+FE=01,进 ...
- KVO VS isa : KVO 建立在 KVC 之上
Key-Value Observing (KVO) 建立在 KVC 之上,它通过重写 KVC 和监听 setter 方法,向外发送通知. https://blog.csdn.net/y55091811 ...
- 联想lenovo 家用电脑安装win7 无法引导问题(新电脑安装系统时提示File:\Boot\BCD错误解决方案)
安装方式 : 1.进入 PE 2.用 EasyimageX 恢复 GHO镜像 3.重启后出现 原因: 主要 是安装win7 时,格式 化选择为GUID模式. 处理: win7 以后,格式华时选择MB ...
- 结构化数据、半结构化数据、非结构化数据——Hadoop处理非结构化数据
刚开始接触Hadoop ,指南中说Hadoop处理非结构化数据,学习数据库的时候,老师总提结构化数据,就是一张二维表,那非结构化数据是什么呢?难道是文本那样的文件?经过上网搜索,感觉这个帖子不错 网址 ...
- Springboot - -web应用开发-Servlets, Filters, listeners
一.Web开发使用 Controller 基本上可以完成大部分需求,但是我们还可能会用到 Servlet. Filter. Listener等等 二.在spring boot中的三种实现方式 方法一: ...
- 二叉排序树(B-Tree)-c实现
这个二叉排序树写完了,虽然还有些bug,但还是很高兴的. 主要实现二叉排序树的构建.(*表示稍微重要点) 二叉排序树的打印. 二叉排序树的删除. 代码里的三种情况都测了 顺便附送一个简单的中序遍历,递 ...
- 《virtual san 最佳实践》节选 Virtual SAN的发展与现状
Virtual SAN的发展与现状Virtual SAN已经迭代更新到第四代,即Virtual SAN 6.2.通过三次主版本迭代,Virtual SAN已经成为一款非常成熟的软件定义存储软件.在此, ...
- Android群英传-拼图游戏puzzle-6点吐槽
一.缘由 经常写文章,混了一些C币.最近在深入学习Android应用开发,就从商城里买了一本<Android群英传>.这本书的内容,不是纯粹的入门那种,分几个章节,重点讲解Activit ...