Educational Codeforces Round 25 D. Suitable Replacement
来源:互联网 发布:seo手机搜索快速排名 编辑:程序博客网 时间:2024/06/08 06:17
传送门
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.
题意:给你一个长度为1e6串,下面给一个模版串,问你输出最大使用下面的模版的串。?是可以替代为任意字符的地方。
做法:看代码。
//china no.1#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e6+100;const double EPS=1e-7;const int MOD=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W whileinline int Scan(){ int res=0,ch,flag=0; if((ch=getchar())=='-')flag=1; else if(ch>='0' && ch<='9')res=ch-'0'; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0'; return flag ? -res : res;}int main(){string s,t;int i,j,hash[26]={0};cin>>s>>t;for(i=0;i<s.size();i++) hash[s[i]-97]++;//把s[i]的每个字符都记录下来。int z=0;for(i=0;i<s.size();i++) {if(s[i]=='?')//当然?里面应该是把t串的字符从头到尾的用一遍这个串就至少有了一个t串 //但有可能本来s串里有t串的部分字母。所以刚开始要存一个s串字符的多少的数组{z++;z%=t.size();if(hash[t[z]-97] > 0)//如果t[z]这个位置s串中有这个字符就跳过{hash[t[z]-97]--;//就把这个字符--i--;//回到上一个位置 下一个位置还是?}elses[i]=t[z];}}cout<<s<<endl;}
- Educational Codeforces Round 25 D. Suitable Replacement
- Educational Codeforces Round 25 D. Suitable Replacement
- Educational Codeforces Round 25 D Suitable Replacement 贪心
- Educational Codeforces Round 25 D. Suitable Replacement【二分】
- Codeforces 825 D Suitable Replacement
- Codeforces 825D Suitable Replacement【贪心】水题
- 【贪心】codeforces 825D Suitable Replacement
- codeforces 825D Suitable Replacement(字母代替?贪心)
- Educational Codeforces Round 21-D
- Educational Codeforces Round 5 D
- Educational Codeforces Round 26 D
- Educational Codeforces Round 25
- Educational Codeforces Round 25
- Educational Codeforces Round 25
- Educational Codeforces Round 25
- Educational Codeforces Round 25
- Educational Codeforces Round 26 D Round Subset
- Codeforces Educational Round 2 D题
- 处理器与NOR flash/pcRAM存储器的错位连接
- APP中英文切换
- CCF 历年真题之学生排队(_1703_2_StudentQueueUp.java)参考答案
- C++ union
- matlab作图时纵轴化成百分比
- Educational Codeforces Round 25 D. Suitable Replacement
- Array-----73. Set Matrix Zeroes
- Tornado异步
- 保证分布式系统数据一致性的6种方案
- Java读取图片时抛Unable to render RenderedOp for this operation
- Apache Hadoop YARN简介
- Scala的基本数据类型及简单使用及循环
- MYSQL update多条Select出来的数据 SQL写法
- Java精选笔记_Servlet技术