【trie树】hdu 3724

妈的,一开始看下去以为跟hdu 2846一样,要处理子串。。。还傻b的用数组,结果MLE大哭,本人最讨厌指针啥的,以为省功夫,谁知道就这样悲剧了!这就教训我有些事情不能省得,要做足!还有,刚开始纠结于那8个浮点数怎么处理,还来搜了一下,发现很简单:先找出8个中最小值minm,然后minm/a[i],若值处在0.95/1.05<=x<=1.0就标记为0,否则就是1!

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;

#define LL long long
#define PI acos(-1.0)
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
double min(double a,double b){return a>b?b:a;}

struct Node
{
       int count;                   //记录遍历到该节点形成的字符串出现的次数
       Node *next[30];              //指向儿子节点
       Node()
       {
             count=1;
             for(int i=0;i<30;i++)
                next[i]=NULL;       //next数组存放儿子的地址!
       }
};
void Insert(Node * &root,char *str)  //向以root为根节点的树中插入字符串str
{
     Node *pos=root;
     int i,id=0;
     if(pos==NULL)
     {
         pos=new Node();
         root=pos;
     }
     for(i=0;str[i];i++)
     {
         id=str[i]-'a';
         if(pos->next[id])           //如果该字符串存在,字符串数量加1
            pos->next[id]->count++;
         else
            pos->next[id]=new Node();   //如果不存在,建立新节点,count=1
         pos=pos->next[id];
     }
}
int ffind(Node * root,char * str)   //在根节点为root的树中查找字符串str
{
    Node *pos=root;
    int i,id=0,ans=0;
    if(pos==NULL)
       return 0;
    for(i=0;str[i];i++)
    {
       id=str[i]-'a';
       if(pos->next[id]==NULL)
          return 0;
       pos=pos->next[id];
       ans=pos->count;
    }
    return ans;
}
int main(){
    int n,m;
    Node *root;
    while(scanf("%d%d",&n,&m)!=EOF){
        int i,j;
        char str[50];
        root=NULL;
        for(i=1;i<=n;i++){
            scanf("%s",str);
            Insert(root,str);
        }
        int ans=0;
        while(m--){
            int k;
            scanf("%d",&k);
            double a[8];
            int cnt=0;

            while(k--){
                double minm=Max;
                for(i=0;i<8;i++){
                scanf("%lf",&a[i]);
                minm=min(minm,a[i]);
            }
            double tmp=0.95/1.05;
            int sum=0;
            for(i=0;i<8;i++){
                double tt=minm/a[i];
                if(tt>=tmp && tt<=1.0)
                {continue;}
                else
                    {sum += (1<<(8-i-1));}
                    }
            str[cnt++]=sum;

            }
            str[cnt]='\0';
            ans+=ffind(root,str);
        }
        printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值