Organize Your Train part II 字典树(此题专卡STL)
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)的更多相关文章
- POJ 3007 Organize Your Train part II (字典树 静态)
Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6478 Acce ...
- POJ 3007 Organize Your Train part II
题意: 如上图所示,将一个字符串进行分割,反转等操作后不同字符串的个数: 例如字符串abba:可以按三种比例分割:1:3:2:2:3:1 部分反转可以得到如下所有的字符串: 去掉重复可以得到六个不同的 ...
- POJ 3007:Organize Your Train part II
Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7561 Acce ...
- 字典树模板题(统计难题 HDU - 1251)
https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...
- CH 1601 - 前缀统计 - [字典树模板题]
题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
- hdu1305 字典树水题
题意: 给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路: 字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...
- poj 3007 Organize Your Train part II(静态字典树哈希)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6700 Accepted: 1922 Description RJ Freigh ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
随机推荐
- .NET 之ViewState的本质
ViewState是如何实现这些功能. 以名值对的方式来存控件的值,和Hashtable的结构类似: 跟踪那些ViewState中出现改变的值,以便对这些脏数据(dirty)进行进一步的处理: 通过序 ...
- Node.js——基本服务开启
标注模式 var http = require('http'); var server = http.createServer(); server.on('request', function (re ...
- Asp.Net 设计模式 之 单例模式
一.设计目的:让项目中只显示一个实例对象 二.设计步骤: 创建一个类: 构建类类型静态变量: 定义返回值类为单例类型的静态方法: 判断静态变量instance是否为空:如果为空,就创建实例,然后给单例 ...
- 分析HTTP 2.0与HTTP 1.1区别
1.什么是HTTP 2.0 HTTP/2(超文本传输协议第2版,最初命名为HTTP 2.0),是HTTP协议的的第二个主要版本,使用于万维网.HTTP/2是HTTP协议自1999年HTTP 1.1发布 ...
- 迅为iTOP-4418/6818开发板MiniLinux下的GPS使用手册
平台:iTOP-4418/6818开发板 系统:MiniLinux 在 Mini Linux 系统环境下 iTOP-4418 和 6818 的 GPS 实验调试步骤.给用户提供了“iTOP-4418- ...
- iTOP-4412开发板全新升级支持4G全网通模块
开发板支持4G,GPS,CAN,485,WIFI蓝牙,重力加速度计,陀螺仪等模块. 核心板参数 尺寸:6cm*7cm 高度:连同连接器在内0.26cm CPU:Exynos4412,四核Cortex- ...
- html 零散问题
1.iconfont的使用 https://www.cnblogs.com/yujihang/p/6706056.html 2.阴影效果比较 box-shadow:0 0 6px #000 inset ...
- vue工程化之去除Eslint验证
有的时候用vue-cli创建好项目之后,写代码时会出现换行和空格报错,出现这么写错误是什么原因呢? 相信第一次接触时有点摸不着头脑.其实是在你用vue-cli脚手架构建项目时用了ESLint代码检查工 ...
- 【软件构造】(转)Java中的comparable和comparator
为了方便阅读和复习,转载至此,原地址:温布利往事的博客 阅读目录 一.Comparable简介 二.Comparator简介 三.Comparable和Comparator区别比较 回到顶部 一.Co ...
- Learning Discriminative and Transformation Covariant Local Feature Detectors实验环境搭建详细过程
依赖项: Python 3.4.3 tensorflow>1.0.0, tqdm, cv2, exifread, skimage, glob 1.安装tensorflow:https://www ...