POJ 3007 Organize Your Train part II map与字典树的比较

点击打开链接

给定一个字符串,从任意位置把它切为两半,得到两条子串

定义 子串1为s1,子串2为s2,子串1的反串为s3,子串2的反串为s4

现在从s1 s2 s3 s4中任意取出两个串组合,问有多少种不同的组合方法

 

规定:

(1)       串Si不能和其 反串 组合

(2)       Si+Sj 与 Sj+Si 是两种组合方式(但未必是不同的组合方式)

///字典树 时间283MS
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1)
#define eps 0.00000001
#define LL long long
using namespace std;
struct node
{
    int flag;
    int next[26];
}p[610000];
int top;
int Creat()
{
    memset(p[top].next,-1,sizeof(p[top].next));
    p[top].flag=0;
    return top++;
}
int Build(char s[])
{
    int k=0;
    int len=strlen(s);
    for(int i=0;iQ;
            geshu++;
            ///Q[s]=1;
            int k=Creat();
            Build(s);
            for(int i=1; i

///map 容器 938MS
 ///必须 先将char[]转化为string类型 然后再map 否则会超时
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1)
#define eps 0.00000001
#define LL long long
using namespace std;
int main()
{
    string c;
    char s[100],s1[100],s2[100],s3[100],s4[100],s5[100],s6[100],s7[100];
    int n;
    while(~scanf("%d",&n))
    {
        while(n--)
        {
            scanf("%s",s);
            int len=strlen(s);
            int geshu=0;
            mapQ;
            geshu++;
            Q[s]=1;
            for(int i=1; i


你可能感兴趣的:(树类)