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 ...
随机推荐
- [转]Spring mvc interceptor配置拦截器,没有登录跳到登录页
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.s ...
- Java 8 – Convert List to Map
Java 8 – Convert List to Map package com.mkyong.java8 public class Hosting { private int Id; private ...
- 温故而知新 前端日志上传新姿势 navigator.sendBeacon(信标)
原文地址:https://mp.weixin.qq.com/s/-moAfEZicrFmun4qfWLdOQ 简单示例js: var data = JSON.stringify({ name: 'Be ...
- 摘抄JPA官方文档原文 防呆
Spring Data JPA - Reference Documentation Oliver GierkeThomas DarimontChristoph StroblMark PaluchVer ...
- 修改hadoop FileUtil.java,解决权限检查的问题
在Hadoop Eclipse开发环境搭建这篇文章中,第15.)中提到权限相关的异常,如下: 15/01/30 10:08:17 WARN util.NativeCodeLoader: Una ...
- 怎么部署 .NET Core Web项目 到linux
.NET Core is free, open source, cross platform and runs basically everywhere. STEP 0 - GET A CHEAP H ...
- Java:多线程,Semaphore同步器
1. 背景 类java.util.concurrent.Semaphore提供了一个计数信号量.通过Semaphore类,可以控制某个资源可被同时访问的个数,通过 acquire() 获取一个许可,如 ...
- jqgrid 设置为每行单选
jqgrid 不支持单选,自己自带了多选multiselect 那么单选怎么做呢,可以参考如下配置 multiselect: true, multiboxonly:true, gridComplete ...
- 菜鸟学JS(三)——自动隐藏的悬浮框
今天写一个小实例,用js和css写一个可以自动隐藏的悬浮框.css肯定是用来控制样式的,js用来控制器显示与隐藏的.显示与隐藏通常有两种方法实现:1,用js控制其显示属性:2,用js控制其大小. 今天 ...
- Eclipse 配置Maven以及修改默认Repository
今天将Eclipse关于Maven的配置总结一下,方便以后配置. 一.配置Maven环境 1.下载apache-maven文件,选择自己需要的版本,地址:http://mirrors.cnnic.cn ...