Codeforces 1194C. From S To T
首先贪心, $S$ 能和 $T$ 匹配就要尽量匹配,剩下的才让 $P$ 来补
在 $S$ 全部匹配上的情况下,看看 $P$ 是否有足够的字符即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=;
int Q,n,m,K,cnt[N],cntt[N];
char s[N],t[N],p[N];
bool vis[N];
int main()
{
Q=read();
while(Q--)
{
scanf("%s",s+); scanf("%s",t+); scanf("%s",p+);
int n=strlen(s+),m=strlen(t+),K=strlen(p+);
if(n>m) { printf("NO\n"); continue; }
memset(vis,,sizeof(vis));
for(int i=;i<;i++) cnt[i]=cntt[i]=;
for(int i=;i<=K;i++) cnt[p[i]-'a']++;
int l=,p=;
for(int i=;i<=m;i++)
{
if(t[i]!=s[p]) continue;
vis[i]=; p++; if(p>n) break;
}
if(p<=n) { printf("NO\n"); continue; }
bool GG=;
for(int i=;i<=m;i++)
if(!vis[i])
{
cntt[t[i]-'a']++;
if(cntt[t[i]-'a']>cnt[t[i]-'a']) GG=;
}
if(GG) printf("NO\n");
else printf("YES\n");
}
return ;
}
Codeforces 1194C. From S To T的更多相关文章
- Codeforces - 1194C - From S To T - 子序列 - 排序
https://codeforces.com/contest/1194/problem/C 好像没什么好说的,要能构造s必须是t的子序列,并且相差的字符集合d是p的子集. 用双指针法求两遍子序列就可以 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 2016 ICPC 大连网络赛 部分题解
先讲1007,有m个人,n种石头,将n种石头分给m个人,每两个人之间要么是朋友关系,要么是敌人关系,朋友的话他们必须有一种相同颜色的石头,敌人的话他们必须所有石头的颜色都不相同.另外,一个人可以不拥有 ...
- Eclipse改变成炫酷黑色主题
有一个款Eclipse插件EclipseColorTheme,其官网地址是http://eclipsecolorthemes.org/,可以直接使用大量内置的样式主题模板,如果还不能满足你自己的个性化 ...
- TCP输出 之 tcp_write_xmit
概述 tcp_write_xmit函数完成对待发送数据的分段发送,过程中会遍历发送队列,进行窗口检查,需要TSO分段则分段,然后调用tcp_transmit_skb发送数据段: 源码分析 static ...
- 基于XML的AOP配置(2)-环绕通知
配置方式: <aop:config> <aop:pointcut expression="execution(* com.itheima.service.impl.*.*( ...
- Ngrinder脚本开发各细节锦集(groovy)
Ngrinder脚本开发各细节锦集(groovy) 1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStrin ...
- vue 的多页面应用
vue-cli3 中构建多页面的应用 第一步:先创建一个 vue-cli3 的项目:vue create app 然后运行项目:npm run serve 现在开始多页面的应用: 首先在 src 的目 ...
- 【.net core 0基础】创建你的第一个.net core应用
1.下载.NET core相应的SDK,https://dotnet.microsoft.com/download 2.安装完成后,打开命令提示符,输入命令 dotnet,检查是否正确安装,如果命令能 ...
- Oracle 设置主键自增长
如果想在Oracle数据库里实现数据表主键自增,我们似乎没有办法像MySql般直接定义列的属性来实现.不过对于这个数据库的常用功能,我们还是有办法实现的.这里将展示使用触发器来实现主键自增. 1.准备 ...
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
package DisplayAuthors; import java.sql.*; public class DisplayAuthors { private static final Str ...
- JAVA记事本的图形用户界面应用程序含加密
JAVA记事本的图形用户界面应用程序 加密 题目简介: 整体分析: 实验代码: import java.awt.EventQueue; import java.awt.event.ActionEven ...