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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Django 详解
Django是一个开源的Web应用框架,由Python写成.采用MVC的软件设计模式,主要目标是使得开发复杂的.数据库驱动的网站变得简单.Django注重组件的重用性和“可插拔性”,敏捷开发和DRY法 ...
- HDX Insight Installation & Configuration
NetScaler Insight Center 11.1 Installation & Configuration NetScaler Insight Center 11.0 Insta ...
- 19个JavaScript简化编码小技巧
这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...
- html上传图片后,在页面显示上传的图片
html上传图片后,在页面显示上传的图片 1.html <form class="container" enctype="multipart/form-data&q ...
- Python中导入类
python导入类与导入函数,模块基本一样,一个模块fun,其中包含三个类 class Dog(): def __init__(self,name): self.name=name def bark( ...
- Thread 源码阅读
Thread 属性说明 /** * 程序中的执行线程 * @since 1.0 */ public class Thread implements Runnable { /* Make sure re ...
- 小程序API:wx.showActionSheet 将 itemList动态赋值
1.发现问题: 小程序调用API:wx.showActionSheet 时发现无论如何都不能将其属性itemList动态赋值. 2.分析问题: 首先我认为可能是格式的问题,itemList必须要求格式 ...
- Hibernate3核心API-Configuration类
- Failed to install the following Android SDK packages as some licences have not been accepted.
问题描述: 执行gradle tasks报错: gradle tasks > Configure project :app Exception /package.xml. Probably th ...
- shell中变量计算
year=44 1.let,不需要$引用变量 let m=year+3 echo $m 2.(()) m=$((year+3)) 3.[ ],注意两边一定要有空格 m=$[ year+3 ] 4. ...