D. Suitable Replacement

这个题统计出 s 和 t 中的各字母个数以及“?”的个数,直接暴力即可,s中不足的字母可用 “?“来替代

这个题的另一种解法是二分 s 中可以出现的 t 的次数,从而找到最大的 the suitability of string s .

代码:

// Created by CAD on 2019/8/6.
#include <bits/stdc++.h> #define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f
#define PII pair<int,int>
#define PIII pair<pair<int,int>,int>
#define mst(name, value) memset(name,value,sizeof(name))
#define FOPEN freopen("C:\\Users\\14016\\Desktop\\cad.txt","r",stdin)
#define test(n) cout<<n<<endl
using namespace std; const int maxn=1e6+5;
int a[30],b[30];
queue<char> ans; int main()
{
ios::sync_with_stdio(false);
string s,t;
cin>>s>>t;
for(auto i: s)
{
if(i=='?') a[0]++;
else a[i-'a'+1]++;
}
for(auto i:t)
b[i-'a'+1]++;
while(a[0]>0)
{
for(int i=1;i<=26;++i)
{
if(a[i]>=b[i]) a[i]-=b[i];
else
{
for(int j=1;j<=b[i]-a[i];j++) ans.push((char)(i+'a'-1)),a[0]--;
a[i]=0;
}
if(a[0]<=0) break;
}
}
for(auto i:s)
{
if(i=='?') cout<<ans.front(),ans.pop();
else cout<<i;
}
cout<<endl;
return 0;
}

Suitable Replacement的更多相关文章

  1. Codeforces 825D Suitable Replacement - 贪心 - 二分答案

    You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...

  2. Educational Codeforces Round 25 D - Suitable Replacement(贪心)

    题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...

  3. Python中文乱码

    1,注意:请使用智慧型浏览器 "CHROME" 配合理解和运作本文中提到的程序. 2,提示:谷歌的CHROME浏览器是迄今为止最智慧的浏览器,没有之一,只有第一. 3,谷歌的CHR ...

  4. Django 源码小剖: Django ORM 查询管理器

    ORM 查询管理器 对于 ORM 定义: 对象关系映射, Object Relational Mapping, ORM, 是一种程序设计技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换.从 ...

  5. Django ORM 查询管理器

    Django ORM 查询管理器 ORM 查询管理器 对于 ORM 定义: 对象关系映射, Object Relational Mapping, ORM, 是一种程序设计技术,用于实现面向对象编程语言 ...

  6. Educational Codeforces Round 25 A,B,C,D

    A:链接:http://codeforces.com/contest/825/problem/A 解题思路: 一开始以为是个进制转换后面发现是我想多了,就是统计有多少个1然后碰到0输出就行,没看清题意 ...

  7. AMQP 0.9.1和1.0协议差别以及rabbitmq支持情况

    RabbitMQ implements AMQP 1.0 via a plugin. However, AMQP 1.0 is a completely different protocol than ...

  8. python:OS模块

    r"""OS routines for NT or Posix depending on what system we're on. This exports: - al ...

  9. 反接保护电路 Reverse Voltage Protection

    Reverse Voltage Protection I've long wanted to pull together some reverse polarity protection ideas ...

随机推荐

  1. JavaScript设计模式(策略模式)

    策略模式的定义是:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换.将不变的部分和变化的部分隔开是每个设计模式的主题,策略模式也不例外,策略模式的目的就是将算法的使用与算法的实现分离开来 ...

  2. Java8排序

    @Data @AllArgsConstructor @NoArgsConstructor public class Apple { private int wight; } 排序 List<In ...

  3. asp.net 8 Request,Response,Server

    Request成员: 1.Request.UrlReferrer 获取请求的来源,可以防盗链 Response.Write(Request.Url.ToString());//获取当前请求的URL地址 ...

  4. gperftools cpp wrapper

    gperftools cpp wrapper // Compile command : ${CXX} -o test_profiler.elf -DUSE_GPERFTOOLS -DDEBUG -D_ ...

  5. ZROI Day1 比赛解题报告

    ZROI Day1 比赛解题报告 版权原因不提供题面相关信息 序 前天晚上搞得比较晚,然后早上做题很没状态,刚看到T1发现没什么思路就有点慌,赶紧看了看T2,T3, 发现T3暴力很好打,T2想了一想可 ...

  6. TCP/IP协议栈各个层次及分别的功能

    网络接口层:这是协议栈的最低层,对应OSI的物理层和数据链路层,主要完成数据帧的实际发送和接收.网络层:处理分组在网络中的活动,例如路由选择和转发等,这一层主要包括IP协议.ARP.ICMP协议等.传 ...

  7. win10下当前目录右键添加CMD快捷方式

    在某个文件夹下右键打开cmd,这样不用每次都在默认情况下切换目录.无奈win10 1703版本下shift+右键不能打开cmd,只能打开powershell. 首先,在桌面新建一个文本文档. Wind ...

  8. 阿里云 elasticsearch 增删改查

    kibana 控制台 # 查询所有数据 GET /yixiurds_dev/_search { "query": { "match_all": { } } } ...

  9. frp 路由穿透(github开源穿透软件)

    server配置(windows):下载: https://github.com/fatedier/frp/releases [common] # 服务器端端口 bind_port = # 客户端连接 ...

  10. another-redis-desktop-manager

    brew cask install another-redis-desktop-manager