Codeforces Round #256 (Div. 2) B (448B) Suffix Structures
题意就是将第一个字符串转化为第二个字符串,支持两个操作。一个是删除,一个是更换字符位置。
简单的字符串操作!。
AC代码例如以下:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define M 50010
#define inf 100000000
using namespace std; char a[1005],b[1005];
int la,lb; bool automaton()
{
int i=0,j=0,flag=0;
while(a[i]!='\0')
{
if(a[i]==b[j])
{
i++;
j++;
flag++;
}
else
{
i++;
}
}
if(flag==lb) return true;
return false;
} int main()
{
int i,j;
int c[500],d[500];
cin>>a;
cin>>b;
la=strlen(a);
lb=strlen(b);
if(lb>la)
{
printf("need tree\n");
return 0;
}
if(la==lb)
{
memset(c,0,sizeof c);
memset(d,0,sizeof d);
for(i=0;i<la;i++)
c[a[i]]++;
for(i=0;i<lb;i++)
d[b[i]]++;
int ans=0;
for(i='a';i<='z';i++)
if(c[i]==d[i])
ans++;
if(ans==26)
{
printf("array\n");
return 0;
}
}
else if(automaton())
{
printf("automaton\n");
return 0;
}
memset(c,0,sizeof c);
memset(d,0,sizeof d);
int anss=0;
for(i=0;i<lb;i++)
d[b[i]]++;
for(i=0;i<la;i++)
c[a[i]]++;
for(i='a';i<='z';i++)
if(d[i]!=0)
anss++;
int an=0;
for(i='a';i<='z';i++)
if(c[i]>=d[i]&&d[i]!=0)
an++;
//cout<<an<<" "<<anss<<endl;
if(an==anss)
{
printf("both\n");
return 0;
}
printf("need tree\n"); return 0;
}
Codeforces Round #256 (Div. 2) B (448B) Suffix Structures的更多相关文章
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
- Codeforces Round #309 (Div. 1) A(组合数学)
题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...
- Codeforces Round #327 (Div. 2)B(逻辑)
B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #254 (Div. 2)D(预计)
D. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #260 (Div. 1) Boredom(DP)
Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #392(Div 2) 758F(数论)
题目大意 求从l到r的整数中长度为n的等比数列个数,公比可以为分数 首先n=1的时候,直接输出r-l+1即可 n=2的时候,就是C(n, 2)*2 考虑n>2的情况 不妨设公比为p/q(p和q互 ...
- Codeforces Round #532 (Div. 2)- B(思维)
Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...
- Codeforces Round #254 (Div. 2) B (445B)DZY Loves Chemistry
推理可得终于结果为2的(n-可分组合数)次方. 问题是怎么求出可分组合数,深搜就可以,当然并查集也能够. AC代码例如以下: 深搜代码!!! #include<iostream> #inc ...
- Codeforces Round #597 (Div. 2)D(最小生成树)
/*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/ #def ...
随机推荐
- C#基础第六天-作业答案-利用面向对象的思想去实现名片
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Nginx(五):浏览器本地缓存设置
浏览器缓存(BrowserCaching) 浏览器缓存是为了加速浏览,浏览器在用户磁盘上,对最近请求过的文档进行存储.当访问者再次请求这个页面时,浏览器就可以从本地磁盘显示文档,这样,就可以加速页面的 ...
- docker容器网络通信原理分析
概述 自从docker容器出现以来,容器的网络通信就一直是大家关注的焦点,也是生产环境的迫切需求.而容器的网络通信又可以分为两大方面:单主机容器上的相互通信和跨主机的容器相互通信.而本文将分别针对这两 ...
- HTC T329手机如何删除系统自带的软件?HTC一键解锁、获取ROOT权限、豌豆荚删除系统软件
手头一部HTC T329T手机,机上默认装载的软件实在太多了,居然占用了4页.用360手机卫士并不能删除系统软件(不能获取ROOT权限).查网上查询,总结要删除系统软件步骤如下(本人不刷机,只是想删除 ...
- javascript 获取函数形参个数
分享下javascript获取函数形参个数的方法. /** * 获取函数的形参个数 * @param {Function} func [要获取的函数] * @return {*} [形参的数组或und ...
- CentOS7静态IP设置
[root@localhost network-scripts]# pwd /etc/sysconfig/network-scripts [root@localhost network-scripts ...
- JavaWEB springmvc 使用定时任务
1.配置web.xml 在web.xml配置使用springmvc框架,其他配置略. <display-name>xxx.com</display-name> <!-- ...
- Spark VS Presto VS Impala
https://www.quora.com/What-is-the-difference-between-Spark-and-Presto
- PLSA及EM算法
前言:本文主要介绍PLSA及EM算法,首先给出LSA(隐性语义分析)的早期方法SVD,然后引入基于概率的PLSA模型,其参数学习采用EM算法.接着我们分析如何运用EM算法估计一个简单的mixture ...
- linux命令(46):批量更改文件后缀,文件名
linux shell 1.要将所有 jpeg的后缀名图片文件修改为 jpg文件. rename .jpeg .jpg *.jpeg