Educational Codeforces Round 25 D - Suitable Replacement(贪心)
题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多。
解题思路: 因为知道s中的字符位置可以交换无数次,所以只要s中含有可以组成t的字符就一定可以出现子串t。所以就是要令t中的字符数量尽量平均地分布在s中。
代码:
#include<iostream>
#include<string>
using namespace std;
int str[]; int main(){
string s,t;
cin>>s>>t;
for(int i=;i<s.size();i++){
if(s[i]!='?')
str[s[i]-'a']++;
}
int k=;
int d=t.size();
for(int i=;i<s.size();i++){
if(s[i]=='?'){
k++;
k%=d;
//说明这个字符出现次数比较多,把机会让给出现次数较少的字符
if(str[t[k]-'a']>){
str[t[k]-'a']--;
i--;
}
else
s[i]=t[k];
}
}
cout<<s<<endl;
return ;
}
Educational Codeforces Round 25 D - Suitable Replacement(贪心)的更多相关文章
- Educational Codeforces Round 25 E. Minimal Labels&&hdu1258
这两道题都需要用到拓扑排序,所以先介绍一下什么叫做拓扑排序. 这里说一下我是怎么理解的,拓扑排序实在DAG中进行的,根据图中的有向边的方向决定大小关系,具体可以下面的题目中理解其含义 Educatio ...
- Educational Codeforces Round 25 A,B,C,D
A:链接:http://codeforces.com/contest/825/problem/A 解题思路: 一开始以为是个进制转换后面发现是我想多了,就是统计有多少个1然后碰到0输出就行,没看清题意 ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...
- Educational Codeforces Round 2 C. Make Palindrome 贪心
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Educational Codeforces Round 25 Five-In-a-Row(DFS)
题目网址:http://codeforces.com/contest/825/problem/B 题目: Alice and Bob play 5-in-a-row game. They have ...
- Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图
E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 25 C. Multi-judge Solving
题目链接:http://codeforces.com/contest/825/problem/C C. Multi-judge Solving time limit per test 1 second ...
- Educational Codeforces Round 25 B. Five-In-a-Row
题目链接:http://codeforces.com/contest/825/problem/B B. Five-In-a-Row time limit per test 1 second memor ...
随机推荐
- POJ.3279 Fliptile (搜索+二进制枚举+开关问题)
POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...
- C之Volatile关键字的介绍与使用20170724
volatile 的意思是“易失的,易改变的”. 一.volatile的引入 这个限定词的含义是向编译器指明变量的内容可能会由于其他程序的修改而变化.通常在程序中申明了一个变量时,编译器会尽量把它存放 ...
- restful风格请求及都是 / 的请求及参数也在请求的/中
前台请求的样式: http://localhost:8080/item/88909 其中参数就是最后的 商品id号 88909 后台Controller中取出参数的方法: @Controller p ...
- HDU--1010
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 分析:dfs+奇偶剪枝. Tempter of the Bone #include<c ...
- discuz开发,登录次数过多,锁定解决方法
到数据库里的表找到pre_common_failedlogin 和pre_ucenter_failedlogins清空里面的内容即可. truncate table pre_common_failed ...
- Python学习笔记(四十九)爬虫的自我修养(一)
论一只爬虫的自我修养 URL的一般格式(带括号[]的为可选项): protocol://hostname[:port]/path/[;parameters][?query]#fragment URL由 ...
- Grass is Green
Root 3719 - Grass is Green Time limit: 3.000 seconds This year exactly n <tex2html_verbatim_ma ...
- c++刷题(6/100)最长上升子序列
题目一:区间子数组个数 给定一个元素都是正整数的数组A ,正整数 L 以及 R (L <= R). 求连续.非空且其中最大元素满足大于等于L 小于等于R的子数组个数. 例如 : 输入: A = ...
- A .Gaby And Addition (Gym - 101466A + 字典树)
题目链接:http://codeforces.com/gym/101466/problem/A 题目: 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 思路: ...
- 【译】DTD - Entities
原文:DTD - Entities 实体用于定义XML文档中特殊字符的快捷方式. 实体主要有四种类型: 内置实体(Built-in entities) 字符实体(Character entities) ...