Organize Your Train part II
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8787   Accepted: 2490

Description

RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure 1.


Figure 1: Layout of the exchange lines

A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are denoted by 26 lowercase letters from "a" to "z". The cars of the same type are indistinguishable from each other, and each car's direction doesn't matter either. Thus, a string of lowercase letters of length 2 to 72 is sufficient to completely express the configuration of a train.

Upon arrival at the exchange lines, a train is divided into two sub-trains at an arbitrary position (prior to entering the storage lines). Each of the sub-trains may have its direction reversed (using the reversal line). Finally, the two sub-trains are connected in either order to form the final configuration. Note that the reversal operation is optional for each of the sub-trains.

For example, if the arrival configuration is "abcd", the train is split into two sub-trains of either 3:1, 2:2 or 1:3 cars. For each of the splitting, possible final configurations are as follows ("+" indicates final concatenation position):

  [3:1]
abc+d cba+d d+abc d+cba
[2:2]
ab+cd ab+dc ba+cd ba+dc cd+ab cd+ba dc+ab dc+ba
[1:3]
a+bcd a+dcb bcd+a dcb+a

Excluding duplicates, 12 distinct configurations are possible.

Given an arrival configuration, answer the number of distinct configurations which can be constructed using the exchange lines described above.

Input

The entire input looks like the following.

the number of datasets = m
1st dataset 
2nd dataset 
... 
m-th dataset

Each dataset represents an arriving train, and is a string of 2 to 72 lowercase letters in an input line.

Output

For each dataset, output the number of possible train configurations in a line. No other characters should appear in the output.

Sample Input

4
aa
abba
abcd
abcde

Sample Output

1
6
12
18

Source

set 和 string 都不让用,只能手写strcat

#include <iostream>
#include <cstdio>
#include<set>
#include <vector>
#include <cstring>
#include <list>
#include <queue>
#include <algorithm>
#include<functional>
#include <stack>
#include<string>
const int MAXN = 1e5 + ;
#define INF 0x3f3f3f3f
const unsigned long long P = ;
typedef unsigned long long ULL;
using namespace std;
//set + string 瞎搞被卡了
//用字典树做
struct node
{
bool been;
int index;
int Next[];
};
node a[MAXN];
int tot = , ans = ;
inline int new_node()
{
for (int i = ; i < ; i++)
a[tot].Next[i] = -;
a[tot].index = tot;
a[tot].been = false;
return tot++;
}
void insert(const char s[], int l, int p)
{
int tmp = , cnt = ;
while (cnt < l)
{
int k = s[cnt] - 'a';
if (a[p].Next[k] == -)
a[p].Next[k] = new_node();
p = a[p].Next[k];
cnt++;
}
if (!a[p].been)
a[p].been = , ans++;
}
char tmp[][];
void cat(int i, int r, int L, char* a, char* b, char* c)
{
int p = ;
for (int j = ; j < i; j++)
c[p++] = a[j];
for (int j = ; j < L - i; j++)
c[p++] = b[j];
insert(c, L, r);
}
int main()
{
ios::sync_with_stdio();
int T;
cin >> T;
while (T--)
{
ans = ;
tot = ;
int root = new_node();
char str[MAXN];
cin >> str;
int L = strlen(str);
if (L == )
{
cout << << endl;
continue;
}
for (size_t i = ; i < L; i++)
{
for (int j = ; j < i; j++)
tmp[][j] = str[j];
for (int k = i; k < L; k++)
tmp[][k-i] = str[k];
for (int j = ; j < i; j++)//1-3
tmp[][j] = tmp[][i - - j];
for (int k = ; k < L - i; k++)//2-4
tmp[][k] = tmp[][L - i - - k];
cat(i, root, L, tmp[], tmp[], tmp[]);
cat(i, root, L, tmp[], tmp[], tmp[]);
cat(L - i, root, L, tmp[], tmp[], tmp[]);
cat(L - i, root, L, tmp[], tmp[], tmp[]);
cat(i, root, L, tmp[], tmp[], tmp[]);
cat(i, root, L, tmp[], tmp[], tmp[]);
cat(L - i, root, L, tmp[], tmp[], tmp[]);
cat(L - i, root, L, tmp[], tmp[], tmp[]); }
cout << ans << endl;
}
}

Organize Your Train part II 字典树(此题专卡STL)的更多相关文章

  1. POJ 3007 Organize Your Train part II (字典树 静态)

    Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6478   Acce ...

  2. POJ 3007 Organize Your Train part II

    题意: 如上图所示,将一个字符串进行分割,反转等操作后不同字符串的个数: 例如字符串abba:可以按三种比例分割:1:3:2:2:3:1 部分反转可以得到如下所有的字符串: 去掉重复可以得到六个不同的 ...

  3. POJ 3007:Organize Your Train part II

    Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7561   Acce ...

  4. 字典树模板题(统计难题 HDU - 1251)

    https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...

  5. CH 1601 - 前缀统计 - [字典树模板题]

    题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...

  6. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  7. hdu1305 字典树水题

    题意:      给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路:       字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...

  8. poj 3007 Organize Your Train part II(静态字典树哈希)

    Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6700 Accepted: 1922 Description RJ Freigh ...

  9. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

随机推荐

  1. math数学函数

    Console.WriteLine("Math.Sign(12)--->{0})", Math.Sign(12)) Console.WriteLine("math. ...

  2. WPF学习11:基于MVVM Light 制作图形编辑工具(2)

    本文是WPF学习10:基于MVVM Light 制作图形编辑工具(1)的后续 这一次的目标是完成 两个任务. 画布 效果: 画布上,选择的方案是:直接以Image作为画布,使用RenderTarget ...

  3. Toolbar自定义布局

    Toolbar如何使用想必大家清楚地很,实际开发中标题栏的样式各色各样,因此其基本样式便不能满足我们的需求,这就需要我们自定义布局.打开ToolBar源码我们发现它继承ViewGroup,这就表示我们 ...

  4. ESSENTIALS OF PROGRAMMING LANGUAGES (THIRD EDITION) :编程语言的本质 —— (一)

    # Foreword> # 序 This book brings you face-to-face with the most fundamental idea in computer prog ...

  5. iOS定位--CoreLocation框架

    CoreLocation框架的使用 // 首先导入头文件 #import <CoreLocation/CoreLocation.h> CoreLocation框架中所有数据类型的前缀都是C ...

  6. SQL SERVER的数据类型

    1.SQL SERVER的数据类型 数据类弄是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或 ...

  7. Farseer.net轻量级ORM开源框架 V1.x 入门篇:新版本说明

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:没有了 下一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库配置 前言 V1.x版本终于到来了.本次 ...

  8. php 阿里云短信验证码

    阿里云短信服务:https://dysms.console.aliyun.com 1.准备 1.1.创建签名.模板 1.2.创建.使用阿里云秘钥 地址:https://usercenter.conso ...

  9. hdfs深入:03、hdfs的架构以及副本机制和block块存储

    HDFS分布式文件系统设计目标 1.            硬件错误  由于集群很多时候由数量众多的廉价机组成,使得硬件错误成为常态 2.            数据流访问  所有应用以流的方式访问数 ...

  10. [Luogu] P1131 [ZJOI2007]时态同步

    题目描述 题目描述 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字1,2,3…进行标号.电路板的各个节点由若干不相交的导线相连接,且对于电路板的任何 ...