首页 技术 正文
技术 2022年11月6日
0 收藏 618 点赞 458 浏览 884 个字

题意:给一个 s 串和 t 串, s 串中有若干问号,问如何填充问号使得 s 串中字母可以组成最多的 t 串。输出填充后的 s 串。

思路:想了下感觉直接怼有点麻烦,要分情况:先处理已经可以组成 t 串的部分,然后处理 s 串中可以利用的部分,如果还有问号剩余,再直接怼。但如果用二分写就很直观了,直接看最多能组成多少个 t 串。

居然踩了long long的坑感觉自己宛若一个zz。check函数中的计算要用long long防止溢出= =(明明大水题的说。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1e6+;
char s[N],t[N];
int cntS[],cntT[],cntQ;
bool check(int x){
ll tmp=;
for(int i=;i<;i++) if(cntT[i]){
tmp+=max(0LL,1LL*x*cntT[i]-cntS[i]);
}
return tmp<=cntQ;
}
int main(){
scanf("%s%s",s,t);
int ls=strlen(s),lt=strlen(t);
for(int i=;i<ls;i++)
if(isalpha(s[i]))
cntS[s[i]-'a']++;
else cntQ++;
for(int i=;i<lt;i++)
cntT[t[i]-'a']++;
int l=,r=N,x=;
while(l<=r){
int mid=(l+r)>>;
if(check(mid)){
l=mid+;
x=mid;
}else r=mid-;
}
int id=;
for(int i=;i<ls;i++){
if(s[i]=='?'){
while(id<&&cntS[id]>=cntT[id]*x) id++;
if(id<){
printf("%c",'a'+id);
cntS[id]++;
}
else putchar('a');
}else printf("%c",s[i]);
}
puts("");
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902