codeforces 448B. Suffix Structures 解题报告
2024-09-30 07:19:04
题目链接:http://codeforces.com/problemset/problem/448/B
题目意思:给出两种操作automaton:可以删除字符串中任意一个字符; array:交换字符串中任意两位。运用这两种操作的次数不限定,问如何运用这两种操作(或其中一种,或两种结合都不能够)使得字符串 s 转换成字符串 t
昨晚做的时候,顶住疲倦死撑,过不了pretest 5,我以为是因为这组数据:ttauotdf auto,当时没想到怎么做,太困了......今日做才发现原来要用到两个指针!而且我发现好多AC代码根本过不了这组数据,她们输出的竟然是 automaton!!!幸好作者还是起到模范作用滴^_^
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char s[maxn], t[maxn];
int cnt[maxn]; void solve()
{
int ls = strlen(s);
int lt = strlen(t);
memset(cnt, , sizeof(cnt));
for (int i = ; i < ls; i++)
cnt[s[i]-'a']++;
for (int i = ; i < lt; i++)
cnt[t[i]-'a']--;
int aut, arr, both;
aut = arr = both = ;
for (int i = , j = ; i < ls; i++)
{
if (s[i] == t[j])
j++;
if (j == lt)
{
aut ^= ;
break;
}
}
for (int i = ; i < ; i++)
{
arr &= (cnt[i] == );
both &= (cnt[i] >= ); // 这个“=”很重要,因为有可能s中有的字母t没有!
}
if (!aut)
printf("automaton\n");
else if (arr)
printf("array\n");
else if (both)
printf("both\n");
else
printf("need tree\n");
} int main()
{
while (scanf("%s%s", s, t) != EOF)
{
solve();
}
return ;
}
最新文章
- CentOS下解压缩命令
- 【bzoj2333】 [SCOI2011]棘手的操作 可并堆+lazy标记
- Windows命令行重命名文件
- iOS开发UI篇—实现一个私人通讯录小应用【转】
- HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
- A Full Hardware Guide to Deep Learning
- jsp连接MySQL操作GIS地图数据,实现添加point的功能
- 【转】C/C++程序员应聘常见面试题深入剖析
- HTML5小游戏《智力大拼图》发布,挑战你的思维风暴
- Leetcode 197. Rising Temperature
- [Leetcode] Binary tree level order traversal二叉树层次遍历
- android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
- Django03-视图系统views
- golang使用chrome headless获取网页内容
- C++重载操作符自增自减
- postgresql-分页重复数据探索
- 查看电脑保存的wifi密码
- Prism中命令可用性无法自动刷新
- 【CF553E】Kyoya and Train 最短路+cdq分治+FFT
- 有关C#中List排序的总结