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 ...
随机推荐
- git 放弃本地修改(转)
如果在修改时发现修改错误,而要放弃本地修改时, 一, 未使用 git add 缓存代码时. 可以使用 git checkout -- filepathname (比如: git checkout -- ...
- JPA之@GeneratedValue注解(转)
JPA的@GeneratedValue注解,在JPA中,@GeneratedValue注解存在的意义主要就是为一个实体生成一个唯一标识的主键(JPA要求每一个实体Entity,必须有且只有一个主键), ...
- MySQL各类日志文件相关变量介绍
文章转自:http://www.ywnds.com/?p=3721 MySQL各类日志文件相关变量介绍 查询所有日志的变量 1 mysql> show global variables li ...
- LVL类及接口使用介绍(License Verification Library )
原文:http://android.eoe.cn/topic/android_sdk LVL Classes and Interfaces-LVL类和接口 Table 1 lists all of t ...
- windows库的创建和使用:静态库+动态库
windows库的创建和使用:静态库+动态库 一.静态库的创建和使用 1. 静态库创建 (1)首先创建projecttest,測试代码例如以下: 1) test.h void test_print ...
- Tornado中gen.coroutine详解
1.gen.coroutine的作用 自动执行生成器 2.Future对象 在介绍异步使用之前,先了解一下Future对象的作用. Future简单可以理解为一个占位符,将来会执行的对象,类似java ...
- iOS按钮的基本使用代码优化
将图片按钮进行连线, 声明方法同时连接六个按钮 -(void)move:(UIButton *)btn{ // NSLog(@"看见一个美女"); //头尾式动画 //0.开 ...
- 【Spring】Spring Session的简单搭建与源码阅读
搭建一个简单的Spring Session例子 引入依赖包 <dependencies> <dependency> <groupId>org.springframe ...
- Kafka:架构简介【转】
转:http://www.cnblogs.com/f1194361820/p/6026313.html Kafka 架构简介 Kafka是一个开源的.分布式的.可分区的.可复制的基于日志提交的发布订阅 ...
- vue2.0如何自定义全局变量的方法
方法一:http://www.jianshu.com/p/04dffe7a6b74 //在mian.js中写入函数 Vue.prototype.changeData = function (){ al ...