codeforces 825D Suitable Replacement(字母代替?贪心)
来源:互联网 发布:网络114网 编辑:程序博客网 时间:2024/06/16 13:27
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters.
Suitability of string s is calculated by following metric:
Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitability is this number of occurrences.
You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal.
The first line contains string s (1 ≤ |s| ≤ 106).
The second line contains string t (1 ≤ |t| ≤ 106).
Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
If there are multiple strings with maximal suitability then print any of them.
?aa?ab
baab
??b?za
azbz
abcdabacaba
abcd
In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string"baab" also has suitability of 2.
In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
In the third example there are no '?' characters and the suitability of the string is 0.
题目大意:把?替换成其他的小写字母,使得s字符串中t字符串最多
写得很暴力。。。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){char s[1000005],t[1000005];int f[30],f1[30],ff[30];scanf("%s%s",s,t);int n=strlen(s);int m=strlen(t);for(int i=0;i<m;i++){f[t[i]-'a']++;ff[t[i]-'a']++;}for(int i=0;i<n;i++){if(s[i]!='?'){f1[s[i]-'a']++;}}int flag=0,j=0;for(int i=0;i<n;i++){if(s[i]=='?'){while(j<26){if(ff[j]!=0){if(f1[j]){f1[j]--;ff[j]--;continue;}else if(f1[j]==0){printf("%c",j+'a');ff[j]--;break;}}j++;if(j==26){flag++;j=0;for(int i=0;i<26;i++){ff[i]=f[i];}}}}else printf("%c",s[i]);}printf("\n");return 0;}
- codeforces 825D Suitable Replacement(字母代替?贪心)
- Codeforces 825D Suitable Replacement【贪心】水题
- 【贪心】codeforces 825D Suitable Replacement
- Codeforces 825 D Suitable Replacement
- Educational Codeforces Round 25 D Suitable Replacement 贪心
- Educational Codeforces Round 25 D. Suitable Replacement
- Educational Codeforces Round 25 D. Suitable Replacement
- Code Force 825D Suitable Replacement
- Educational Codeforces Round 25 D. Suitable Replacement【二分】
- codeforces825 D. Suitable Replacement 二分答案
- CF825D:Suitable Replacement(字符串)
- CodeForces 825D(贪心)
- codeforces825D-Suitable Replacement
- codeforces 222D Olympiad(贪心)
- CodeForces 128D Numbers(贪心?)
- Codeforces 222D Olympiad(贪心)
- CodeForces 732 D.Exams(二分+贪心)
- CodeForces 35 D.Animals(贪心)
- MS UI Automation简介
- 两种方法解决 "The License CNEKJPQZEX- has been cancelled..." 问题
- ZOJ
- 设计模式-策略模式---Strategy(对象行为型)
- 字符串相关函数、strcat,strcpy,strcmp
- codeforces 825D Suitable Replacement(字母代替?贪心)
- EXCEL转PDF方法之使用PDF虚拟打印机生成PDF文件
- Java学习路程掌握的技能清单
- 移动 VR 究竟有多少坑?高通、ARM、谷歌、Unity Technologies 的专家们这么看 | SIGGRAPH 2017 圆桌对话精选
- 【Node.js-5】multer的三种上传情况:单个文件,多个同名文件,多个不同名文件
- Docker安装
- 链式队列创建
- OC基础-02-类和对象
- 实现长按识别webview中的二维码